开发者

organized workingspace in c# form

it's my first time in C# form and I dont know if what I am doing is correct. below is my form workspace in C# and you can see that there's a lot of things there and it's messy...

organized workingspace in c# form

i use the this.BackgroundImage = image; to change the background image of the form and i just turn the visible property of each control on whenever they are needed so that it look nice when i run the app (im still not finish with it though, it's hard to work in a form that's messy)

organized workingspace in c# form

is there anyway i can work in an organized way like i could work with a lot of forms, instead of one, and just interconnect them like in powerpoint where you could have many slides and just use a hyperlink to point to other slides... please help... and here's my code (sorry for the noob coding style)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using Microsoft.VisualBasic;

namespace PProj1
{
    public partial class Form1 : Form
    {
        publi开发者_C百科c Form1()
        {
            InitializeComponent();
            backfromaboutandhow.Visible = false;
            nextbutton.Visible = false;
            backfromreserve.Visible = false;
            textBox1.Visible = false;
            textBox2.Visible = false;
            textBox3.Visible = false;
            textBox4.Visible = false;
            label1.Visible = false;
            label2.Visible = false;
            label3.Visible = false;
            label4.Visible = false;
            label5.Visible = false;
            finish.Visible = false;
            backtoreserve.Visible = false;
            N1.Visible = false;
            N2.Visible = false;
            N3.Visible = false;
            N4.Visible = false;
            N5.Visible = false;
            N6.Visible = false;
            N7.Visible = false;
            N8.Visible = false;
            S1.Visible = false;
            S2.Visible = false;
            S3.Visible = false;
            S4.Visible = false;
            S5.Visible = false;
            S6.Visible = false;
            S7.Visible = false;
            S8.Visible = false;
            E1.Visible = false;
            E2.Visible = false;
            E3.Visible = false;
            E4.Visible = false;
            W1.Visible = false;
            W2.Visible = false;
            W3.Visible = false;
            NW1.Visible = false;
            NW2.Visible = false;
            NE1.Visible = false;
            NE2.Visible = false;
            SW.Visible = false;
            SE.Visible = false;
        }

        OleDbConnection con;
        OleDbCommand cmd;
        OleDbDataAdapter adapter;
        DataSet ds;

        private void pictureBox1_MouseHover(object sender, EventArgs e)
        {
            aboutoldtrafford.Location = new Point(16, 9);
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            aboutoldtrafford.Location = new Point(9, 9);
        }

        private void pictureBox2_MouseHover(object sender, EventArgs e)
        {
            howtogetthere.Location = new Point(16, 62);
        }

        private void pictureBox2_MouseLeave(object sender, EventArgs e)
        {
            howtogetthere.Location = new Point(9, 62);
        }

        private void pictureBox3_MouseHover(object sender, EventArgs e)
        {
            reserveaticket.Location = new Point(16, 113);
        }

        private void pictureBox3_MouseLeave(object sender, EventArgs e)
        {
            reserveaticket.Location = new Point(9, 113);
        }

        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            Image image = Properties.Resources.about;
            this.BackgroundImage = image;
            aboutoldtrafford.Visible = false;
            howtogetthere.Visible = false;
            reserveaticket.Visible = false;
            backfromaboutandhow.Visible = true;
        }

        private void pictureBox4_MouseHover(object sender, EventArgs e)
        {
            backfromaboutandhow.Location = new Point(566, 511);
        }

        private void pictureBox4_MouseLeave(object sender, EventArgs e)
        {
            backfromaboutandhow.Location = new Point(559, 511);
        }

        private void pictureBox4_MouseClick(object sender, MouseEventArgs e)
        {
            backfromaboutandhow.Visible = false;
            Image image = Properties.Resources.oldtraffordwelcome1;
            this.BackgroundImage = image;
            aboutoldtrafford.Visible = true;
            howtogetthere.Visible = true;
            reserveaticket.Visible = true;

        }

        private void pictureBox2_MouseClick(object sender, MouseEventArgs e)
        {
            Image image = Properties.Resources.howto;
            this.BackgroundImage = image;
            aboutoldtrafford.Visible = false;
            howtogetthere.Visible = false;
            reserveaticket.Visible = false;
            backfromaboutandhow.Visible = true;
        }

        private void pictureBox3_MouseClick(object sender, MouseEventArgs e)
        {
            Image image = Properties.Resources.reg1;
            this.BackgroundImage = image;
            aboutoldtrafford.Visible = false;
            howtogetthere.Visible = false;
            reserveaticket.Visible = false;
            backfromaboutandhow.Visible = false;
            textBox1.Visible = true;
            textBox2.Visible = true;
            textBox3.Visible = true;
            textBox4.Visible = true;
            label1.Visible = true;
            label2.Visible = true;
            label3.Visible = true;
            label4.Visible = true;
            nextbutton.Visible = true;
            backfromreserve.Visible = true;
        }

        private void pictureBox5_MouseHover(object sender, EventArgs e)
        {
            nextbutton.Location = new Point(545, 463);
        }

        private void pictureBox5_MouseLeave(object sender, EventArgs e)
        {
            nextbutton.Location = new Point(539, 463);
        }

        private void pictureBox6_MouseHover(object sender, EventArgs e)
        {
            backfromreserve.Location = new Point(30, 463);
        }

        private void pictureBox6_MouseLeave(object sender, EventArgs e)
        {
            backfromreserve.Location = new Point(36, 463);
        }

        private void pictureBox6_MouseClick(object sender, MouseEventArgs e)
        {
            nextbutton.Visible = false;
            backfromreserve.Visible = false;
            Image image = Properties.Resources.oldtraffordwelcome1;
            this.BackgroundImage = image;
            aboutoldtrafford.Visible = true;
            howtogetthere.Visible = true;
            reserveaticket.Visible = true;
            textBox1.Visible = false;
            textBox2.Visible = false;
            textBox3.Visible = false;
            textBox4.Visible = false;
            label1.Visible = false;
            label2.Visible = false;
            label3.Visible = false;
            label4.Visible = false;
            label5.Visible = false;
            finish.Visible = false;
            backtoreserve.Visible = false;

        }

        private void pictureBox5_MouseClick(object sender, MouseEventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "")
            {
                Image image = Properties.Resources.reg21;
                this.BackgroundImage = image;

                textBox1.Visible = false;
                textBox2.Visible = false;
                textBox3.Visible = false;
                textBox4.Visible = false;
                label1.Visible = false;
                label2.Visible = false;
                label3.Visible = false;
                label4.Visible = false;
                label5.Visible = false;
                nextbutton.Visible = false;
                backfromreserve.Visible = false;
                finish.Visible = true;
                backtoreserve.Visible = true;
                N1.Visible = true;
                N2.Visible = true;
                N3.Visible = true;
                N4.Visible = true;
                N5.Visible = true;
                N6.Visible = true;
                N7.Visible = true;
                N8.Visible = true;
                S1.Visible = true;
                S2.Visible = true;
                S3.Visible = true;
                S4.Visible = true;
                S5.Visible = true;
                S6.Visible = true;
                S7.Visible = true;
                S8.Visible = true;
                E1.Visible = true;
                E2.Visible = true;
                E3.Visible = true;
                E4.Visible = true;
                W1.Visible = true;
                W2.Visible = true;
                W3.Visible = true;
                NW1.Visible = true;
                NW2.Visible = true;
                NE1.Visible = true;
                NE2.Visible = true;
                SW.Visible = true;
                SE.Visible = true;

            }
            else
            {
                label5.Visible = true;
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            con = new OleDbConnection(@" provider=Microsoft.ace.Oledb.12.0; data source=C:\OldTrafford.accdb; Persist Security Info=False");
            loaddata();
        }
        void loaddata()
        {
            adapter = new OleDbDataAdapter("select * from oldtraff", con);
            ds = new DataSet(); //student-> table name in stud.accdb file
            adapter.Fill(ds, "oldtraff");
            ds.Tables[0].Constraints.Add("pk_ID", ds.Tables[0].Columns[0], true);//creating primary key for Tables[0] in dataset
            //dataGridView1.DataSource = ds.Tables[0];
        }

        private void finish_MouseHover(object sender, EventArgs e)
        {
            finish.Location = new Point(545, 553);
        }

        private void finish_MouseLeave(object sender, EventArgs e)
        {
            finish.Location = new Point(539, 553);
        }

        private void backtoreserve_MouseHover(object sender, EventArgs e)
        {
            backtoreserve.Location = new Point(30, 553);
        }

        private void backtoreserve_MouseLeave(object sender, EventArgs e)
        {
            backtoreserve.Location = new Point(36, 553);
        }

        private void backtoreserve_MouseClick(object sender, MouseEventArgs e)
        {
            Image image = Properties.Resources.reg1;
            this.BackgroundImage = image;
            aboutoldtrafford.Visible = false;
            howtogetthere.Visible = false;
            reserveaticket.Visible = false;
            backfromaboutandhow.Visible = false;
            textBox1.Visible = true;
            textBox2.Visible = true;
            textBox3.Visible = true;
            textBox4.Visible = true;
            label1.Visible = true;
            label2.Visible = true;
            label3.Visible = true;
            label4.Visible = true;
            nextbutton.Visible = true;
            backfromreserve.Visible = true;
            finish.Visible = false;
            backtoreserve.Visible = false;
            N1.Visible = false;
            N2.Visible = false;
            N3.Visible = false;
            N4.Visible = false;
            N5.Visible = false;
            N6.Visible = false;
            N7.Visible = false;
            N8.Visible = false;
            S1.Visible = false;
            S2.Visible = false;
            S3.Visible = false;
            S4.Visible = false;
            S5.Visible = false;
            S6.Visible = false;
            S7.Visible = false;
            S8.Visible = false;
            E1.Visible = false;
            E2.Visible = false;
            E3.Visible = false;
            E4.Visible = false;
            W1.Visible = false;
            W2.Visible = false;
            W3.Visible = false;
            NW1.Visible = false;
            NW2.Visible = false;
            NE1.Visible = false;
            NE2.Visible = false;
            SW.Visible = false;
            SE.Visible = false;
        }
    }
}


You should probably consider using "User Controls" to separate your screens. Each of these controls should manage it's own interactions with the user. If you need to let you main form know what's going on with one of these controls, you can use an event (just like any other type of control).

For the example you've shown, you'd have 5 controls (one for each screen), and maybe a few events on each control which indicate the user has pressed the "Next" button (or whatever).

The main control should change which control is displayed at any given time... and it'll probably be easiest to do this through code instead of the GUI designer.

EDIT:

This link is super old, but it'll give you an idea of what I mean - and save me from making a bunch of screen shots and pasting them in here:

http://msdn.microsoft.com/en-us/library/aa302342.aspx

http://knol.google.com/k/creating-custom-controls-with-c-net#


I think you could make wizard like your application. Also as others mentioned in their answers use user controls to "group" controls to manage them easily.


You could make a usercontrol for each and simply hide/show that usercontrol.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜