For file transfer between the client and server systems we have a GUI designed on the client system using C# windows forms. We have added a lot of background images and text boxes to make the GUI impressive. But whenever we execute the client code, the GUI takes a few seconds to load itself and be stable , before a choice from the GUI can be made. This happens after every request made from the client side GUI.(its like all the form elements vanish and appear again in a short span of time ). Please help with this. May i know the reason for it.
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.Diagnostics;
using System.IO;
namespace Client405
{
public partial class RequestForm : Form
{
#region Variables
internal static ListBox FileListBox;
internal static byte[] RecievedFile = new byte[46000000];
internal static string StoragePath = string.Empty;
internal static bool CacheSelected = false;
internal static string ChosenTech = "Default";
internal static bool EnableCompression = false;
//internal static string FileType;
internal static string SelectedFile = string.Empty;
internal static Stopwatch watch = new Stopwatch();
#endregion
public RequestForm()
{
InitializeComponent();
this.Load += new EventHandler(RequestForm_Load);
this.DoubleBuffered = true;
}
void RequestForm_Load(object sender, EventArgs e)
{
ComprMsgLabel.Text = "Compression Technique chosen is :" + ChosenTech;
FileListBox = new ListBox();
FileName_textBox.Enabled = true;
FileName_textBox.ReadOnly = true;
if (!Connections.SocketConnected())
{
Connections.EstablishConnectionWithServer();
}
if (LoginAuthenticator.registered)
{
EnableCompression = true;
CacheSelected = true;
RegisterlinkLabel.Visible = false;
HighRB.Enabled = true;
LowRB.Enabled = true;
MediumRB.Enabled = true;
CacheMsg_label.Text = "Caching Enabled";
}
else if (!LoginAuthenticator.registered)
{
RegisterlinkLabel.Visible = true;
RegisterlinkLabel.Show();
Logout_Label.Text = "Home Page";
Cache_checkBox.CheckState = CheckState.Unchecked;
Cache_checkBox.Enabled = false;
EnableCompr_checkBox.Enabled = false;
HighRB.Enabled = false;
LowRB.Enabled = false;
MediumRB.Enabled = false;
DefaultRB.Visible = false;
NoneRB.Visible = false;
DefaultRB.Enabled = false;
NoneRB.Enabled = false;
CacheMsg_label.Text = "Caching Disabled";
}
ChosenTech = "None";
LogUser_Label.Text = LogUser_Label.Text + LoginAuthenticator.myCurrentUser;
SetClientInfo();
}
private void SetClientInfo()
{
//LogUser_Label.Text = LoginAuthenticator.myCurrentUser;
HostValue_Label.Text = HelperInfo.HostNameValue;
//Add port info
Port_Value.Text = HelperInfo.PortNumber;
//Add IP address
IPAddr_value.Text = HelperInfo.IPAddress_client;
//Add Gateway info
Gateway_value.Text = HelperInfo.Default_Gateway;
//Add the ip address of server connected to
ServerIP_Value_Label.Text = HelperInfo.Connected_To(Connections.myClientSocket);
if (Connections.myClientSocket.Connected)
{
ONOFF_radio.Text = "Online";
}
else
{
ONOFF_radio.Text = "Offline";
}
}
private void GetFile_Button_Click(object sender, EventArgs e)
{
if ((AudioRB.Checked == false) && (ImageRB.Checked == false) && (TextRB.Checked == false))
{
MessageBox.Show("Please select a File Type");
return;
}
if (SelectedFile == string.Empty)
{
MessageBox.Show("Please Select a File");
return;
}
if (!LoginAuthenticator.registered)
{
FileTransfer.UnRegisteredTransfer();
this.Refresh();
MessageBox.Show("Transaction Completed");
}
if (LoginAuthenticator.registered)
{
DialogResult trans_reqd = DialogResult.No;
//check Cache
if (Cache_checkBox.CheckState == CheckState.Checked)
{
trans_reqd = FileCache.TransactionQuery(RequestForm.SelectedFile);
if (trans_reqd == DialogResult.No)
{
string[] files = { System.IO.Path.Combine(#"D:\\FT\\Cache", RequestForm.SelectedFile), System.IO.Path.Combine(#"D:\\FT\\Downloads", RequestForm.SelectedFile) };
if (System.IO.File.Exists(files[1]))
{
System.IO.File.Delete(files[1]);
}
System.IO.File.Copy(files[0], files[1]);
watch.Stop();
}
else //if not in cacheF
{
FileTransfer.RegisteredTransfer();
}
}
else //if caching not enabled
{
FileTransfer.RegisteredTransfer();
}
this.Refresh();
MessageBox.Show("Transaction Completed");
}
}
private void AudioRB_CheckedChanged(object sender, EventArgs e)
{
ChosenTech = "Default";
if (AudioRB.Checked == true)
{
ImageRB.Checked = false;
TextRB.Checked = false;
EnableCompr_checkBox.CheckState = CheckState.Unchecked;
EnableCompr_checkBox.Visible = false;
EnableCompr_checkBox.Enabled = false;
FileListBox.Hide();
DisplayRadioButtons();
SelectedFile = string.Empty;
FileName_textBox.Text = string.Empty;
FileTransfer.FileType = "Audio";
//ViewFiles_button.Visible = true;
ViewFiles();
}
else if (AudioRB.Checked == false)
{
//ViewFiles_button.Visible = false;
EnableCompr_checkBox.Visible = true;
EnableCompr_checkBox.Enabled = true;
FileListBox.Hide();
}
}
private void ViewFiles()
{
FileTransfer.GetFileNames();
this.Controls.Add(RequestForm.FileListBox);
RequestForm.FileListBox.BringToFront();
RequestForm.FileListBox.Visible = true;
RequestForm.FileListBox.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);
//RequestForm.SelectedFile = FileTransfer.FileListView.SelectedItems[0].Text;
//FileName_textBox.Text = RequestForm.SelectedFile;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
FileName_textBox.Text = FileListBox.SelectedItem.ToString();
RequestForm.SelectedFile = FileName_textBox.Text;
}
private void ImageRB_CheckedChanged(object sender, EventArgs e)
{
ChosenTech = "Default";
if (ImageRB.Checked == true && LoginAuthenticator.registered)
{
AudioRB.Checked = false;
TextRB.Checked = false;
EnableCompr_checkBox.CheckState = CheckState.Unchecked;
EnableCompr_checkBox.Enabled = true;
EnableCompr_checkBox.Visible = true;
FileListBox.Hide();
FileTransfer.FileType = "Image";
SelectedFile = string.Empty;
FileName_textBox.Text = string.Empty;
DisplayRadioButtons();
ViewFiles();
//ViewFiles_button.Visible = true;
}
else if (ImageRB.Checked == true && !LoginAuthenticator.registered)
{
AudioRB.Checked = false;
TextRB.Checked = false;
EnableCompr_checkBox.CheckState = CheckState.Unchecked;
EnableCompr_checkBox.Enabled = false;
EnableCompr_checkBox.Visible = true;
FileListBox.Hide();
FileTransfer.FileType = "Image";
SelectedFile = string.Empty;
FileName_textBox.Text = string.Empty;
DisplayRadioButtons();
ViewFiles();
}
else if (ImageRB.Checked == false)
{
//ViewFiles_button.Visible = false;
RequestForm.FileListBox.Hide();
}
}
private void TextRB_CheckedChanged(object sender, EventArgs e)
{
ChosenTech = "Default";
if (TextRB.Checked == true && LoginAuthenticator.registered)
{
ImageRB.Checked = false;
AudioRB.Checked = false;
EnableCompr_checkBox.CheckState = CheckState.Unchecked;
EnableCompr_checkBox.Enabled = true;
EnableCompr_checkBox.Visible = true;
RequestForm.FileListBox.Hide();
DisplayRadioButtons();
FileTransfer.FileType = "Text";
SelectedFile = string.Empty;
FileName_textBox.Text = string.Empty;
ViewFiles();
//ViewFiles_button.Visible = true;
}
else if (TextRB.Checked == true && !LoginAuthenticator.registered)
{
ImageRB.Checked = false;
AudioRB.Checked = false;
EnableCompr_checkBox.CheckState = CheckState.Unchecked;
EnableCompr_checkBox.Enabled = false;
EnableCompr_checkBox.Visible = true;
RequestForm.FileListBox.Hide();
DisplayRadioButtons();
FileTransfer.FileType = "Text";
SelectedFile = string.Empty;
FileName_textBox.Text = string.Empty;
ViewFiles();
}
else if (TextRB.Checked == false)
{
//ViewFiles_button.Visible = false;
RequestForm.FileListBox.Hide();
}
}
private void Cache_checkBox_CheckedChanged(object sender, EventArgs e)
{
if (Cache_checkBox.Checked)
{
CacheMsg_label.Text = "Caching Enabled";
CacheSelected = true;
}
else
{
CacheMsg_label.Text = "Caching Disabled";
CacheSelected = false;
}
}
private void EnableCompr_checkBox_CheckedChanged(object sender, EventArgs e)
{
DisplayRadioButtons();
}
internal void DisplayRadioButtons()
{
if (EnableCompr_checkBox.CheckState == CheckState.Unchecked)
{
HighRB.Enabled = false;
MediumRB.Enabled = false;
LowRB.Enabled = false;
HighRB.Visible = false;
MediumRB.Visible = false;
LowRB.Visible = false;
DefaultRB.Enabled = false;
DefaultRB.Visible = false;
NoneRB.Enabled = false;
NoneRB.Visible = false;
}
if (EnableCompr_checkBox.Checked && FileTransfer.FileType == null)
{
MessageBox.Show("Please select a FileType.\nAssociated Compression techniques available will be shown.");
EnableCompr_checkBox.CheckState = CheckState.Unchecked;
}
if (EnableCompr_checkBox.Checked && FileTransfer.FileType == "Text" && LoginAuthenticator.registered)
{
DefaultRB.Enabled = true;
DefaultRB.Visible = true;
NoneRB.Visible = true;
NoneRB.Enabled = true;
HighRB.Enabled = false;
MediumRB.Enabled = false;
LowRB.Enabled = false;
HighRB.Visible = false;
MediumRB.Visible = false;
LowRB.Visible = false;
ComprMsgLabel.Text = "Chosen Compression technique : Default";
}
else if (EnableCompr_checkBox.Checked && FileTransfer.FileType == "Text" && !LoginAuthenticator.registered)
{
HighRB.Enabled = false;
MediumRB.Enabled = false;
LowRB.Enabled = false;
HighRB.Visible = false;
MediumRB.Visible = false;
LowRB.Visible = false;
NoneRB.Visible = false;
DefaultRB.Visible = false;
ComprMsgLabel.Text = "Chosen Compression technique : Default";
}
else if (EnableCompr_checkBox.Checked && FileTransfer.FileType == "Image" && LoginAuthenticator.registered)
{
DefaultRB.Enabled = true;
DefaultRB.Visible = true;
NoneRB.Visible = true;
NoneRB.Enabled = true;
HighRB.Enabled = true;
MediumRB.Enabled = true;
LowRB.Enabled = true;
HighRB.Visible = true;
MediumRB.Visible = true;
LowRB.Visible = true;
ChosenTech = "Default";
ComprMsgLabel.Text = "Chosen Compression technique : Default";
}
else if (EnableCompr_checkBox.Checked && FileTransfer.FileType == "Image" && !LoginAuthenticator.registered)
{
HighRB.Enabled = false;
MediumRB.Enabled = false;
LowRB.Enabled = false;
HighRB.Visible = false;
MediumRB.Visible = false;
LowRB.Visible = false;
DefaultRB.Visible = false;
NoneRB.Visible = false;
DefaultRB.Enabled = false;
NoneRB.Enabled = false;
ChosenTech = "VLOW";
ComprMsgLabel.Text = "Chosen Compression technique : " + ChosenTech;
}
}
private void NoneRB_CheckedChanged(object sender, EventArgs e)
{
if (FileTransfer.FileType == "Text" && NoneRB.Checked == true)
{
ChosenTech = "None";
DefaultRB.Checked = false;
}
else if (FileTransfer.FileType == "Image" && NoneRB.Checked == true)
{
ChosenTech = "None";
DefaultRB.Checked = false;
HighRB.Checked = false;
LowRB.Checked = false;
MediumRB.Checked = false;
}
else if (NoneRB.Checked == false)
{
ChosenTech = "Default";
}
ComprMsgLabel.Text = "Compression Technique chosen is :" + ChosenTech;
}
private void Logout_Label_Click(object sender, EventArgs e)
{
Connections.EndConnectionWithServer();
Form1 newForm = new Form1();
LoginAuthenticator.myCurrentUser = string.Empty;
ChosenTech = string.Empty;
FileTransfer.FileType = null;
this.Hide();
newForm.Show();
MessageBox.Show("LogOut successful");
}
private void MediumRB_CheckedChanged(object sender, EventArgs e)
{
if (MediumRB.Checked == true)
{
ChosenTech = "MEDIUM";
HighRB.Checked = false;
LowRB.Checked = false;
NoneRB.Checked = false;
}
else if (MediumRB.Checked == false)
{
ChosenTech = "Default";
}
ComprMsgLabel.Text = "Compression Technique chosen is :" + ChosenTech;
}
private void LowRB_CheckedChanged(object sender, EventArgs e)
{
if (LowRB.Checked == true)
{
ChosenTech = "LOW";
HighRB.Checked = false;
MediumRB.Checked = false;
NoneRB.Checked = false;
}
else if (LowRB.Checked == false)
{
ChosenTech = "Default";
}
ComprMsgLabel.Text = "Compression Technique chosen is :" + ChosenTech;
}
private void HighRB_CheckedChanged(object sender, EventArgs e)
{
if (HighRB.Checked == true)
{
ChosenTech = "HIGH";
LowRB.Checked = false;
MediumRB.Checked = false;
NoneRB.Checked = false;
}
else if (HighRB.Checked == false)
{
ChosenTech = "Default";
}
ComprMsgLabel.Text = "Compression Technique chosen is :" + ChosenTech;
}
private void statistics_button_Click(object sender, EventArgs e)
{
Form2 statForm = new Form2();
statForm.fileType_label.Text = statForm.fileType_label.Text + FileTransfer.FileType;
statForm.fnstat_label.Text = statForm.fnstat_label.Text + SelectedFile;
statForm.ASize_label.Text = statForm.ASize_label.Text + " " + FileTransfer.actualSize + " bytes";
statForm.recSize_label.Text = statForm.recSize_label.Text + " " + FileTransfer.recSize + " bytes";
statForm.rtt_label.Text = statForm.rtt_label.Text + " " + watch.ElapsedMilliseconds + " ms";
long percentage = ((FileTransfer.actualSize - FileTransfer.recSize) * 100) / FileTransfer.actualSize;
statForm.BWsave.Text = statForm.BWsave.Text + " " + percentage + " %";
statForm.Show();
if (watch.ElapsedMilliseconds > 0)
{
MessageBox.Show("The time taken for the transaction is : " + watch.ElapsedMilliseconds);
}
else
{
MessageBox.Show("The time taken for the transaction is : 1000 ");
}
}
private void Folder_Select_Button_Click(object sender, EventArgs e)
{
SaveFileDialog sd = new SaveFileDialog();
sd.InitialDirectory = #"D:\FT\";
sd.Filter = "Text files (*.txt)|*.txt|ImageFiles (*.jpg)|*.jpg | Audio Files (*.mp3)|*.mp3";
sd.ShowDialog();
if (!File.Exists(sd.FileName))
{
FileStream fs = File.Create(sd.FileName);
fs.Close();
}
else
{
FileStream fd = File.Open(sd.FileName, FileMode.OpenOrCreate);
fd.Close();
}
StoragePath = sd.FileName;
}
private void RegisterlinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Connections.EndConnectionWithServer();
//MessageBox.Show("Please Enter the Registration Details. ");
Register regForm = new Register();
regForm.Show();
this.Hide();
}
private void refresh_Click(object sender, EventArgs e)
{
if (FileTransfer.FileType == null)
{
MessageBox.Show("Select a File Type");
}
else
{
ViewFiles();
}
}
private void Setting_Label_Click(object sender, EventArgs e)
{
Process myprocess = new Process();
try
{
myprocess.StartInfo.UseShellExecute = true;
myprocess.StartInfo.FileName = "http://" + HelperInfo.Default_Gateway + "//WANem";
myprocess.Start();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void FileName_textBox_TextChanged(object sender, EventArgs e)
{
}
}
}
Try using below code in your form constructor.
this.DoubleBuffered = true;
It should improve some performance. Windows forms are not made to display lot of images overlapped on each other.
Related
I'm a student working on a GUI using C# Winforms, where the user is able to load an image, paint on it and then save the edited image to his system.
Bitmap b = new Bitmap(imgList);
image.DrawImage(b, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(btm, Point.Empty);
My issue is when I save the edited image from the picturebox it's quality is reduced and it has the heightXwidth of that of the picturebox. I've provided my Form.cs below for reference. Is there any way I can make the edited image to maintain the image quality of the original image?
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SIP_UI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
imagelst = new ImageList();
}
//Declared Variables
private Graphics g;
private Graphics image;
private Bitmap btm;
private SolidBrush c;
private bool drawing = false;
private ImageList imagelst;
private string[] imglst;
private int imgCnt = 1;
private bool saveNxtWasClicked = false;
private bool savePrevWasClicked = false;
private void Form1_Load(object sender, EventArgs e)
{
g = pictureBox1.CreateGraphics();
btm = new Bitmap(pictureBox1.Width, pictureBox1.Height);
image = Graphics.FromImage(btm);
image.Clear(Color.White);
//Status color on default load
pnlStatus.BackColor = Color.DarkGray;
chkbxImageInfo.Checked = false;
if (chkbxImageInfo.Checked == false)
{
txtTestRep.Enabled = false;
txtBoard.Enabled = false;
cmbxPosition.Enabled = false;
}
btnNext.Enabled = true;
btnPrev.Enabled = false;
txtImgNum.Text = "0";
lblTotl.Text = "#";
using (StreamReader streamReaderOpen = new StreamReader("OpenLocation.txt"))
{
string strOpen = streamReaderOpen.ReadLine();
//Check path validity
if (System.IO.Directory.Exists(strOpen))
{
txtOpnPath.Text = strOpen;
}
else
{
txtOpnPath.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
}
}
using (StreamReader streamReaderSave = new StreamReader("SaveLocation.txt"))
{
string strSave = streamReaderSave.ReadLine();
//Check path validity
if (System.IO.Directory.Exists(strSave))
{
txtSavPath.Text = strSave;
}
else
{
txtSavPath.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
}
}
using (StreamReader streamReaderCsv = new StreamReader("CsvLocation.txt"))
{
string strCsv = streamReaderCsv.ReadLine();
//Check path validity
if (System.IO.Directory.Exists(strCsv))
{
txtCsvPath.Text = strCsv;
}
else
{
txtCsvPath.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
}
//Open images from previous folder
if (txtOpnPath.Text.Length > 0)
{
int i = 0;
int numImgs = Directory.GetFiles(txtOpnPath.Text, "*.PNG").Length;
imglst = new string[numImgs];
lblTotl.Text = Convert.ToString(numImgs);
txtImgNum.Text = Convert.ToString(1);
//foreach (var file in Directory.GetFiles(txtOpnPath.Text).Where(f => extensions.Contains(Path.GetExtension(f).ToUpper())))
foreach (var file in Directory.GetFiles(txtOpnPath.Text, "*.PNG"))
{
imglst[i++] = file;
}
if (imglst.Length > 0)
{
drawImage(imglst[0]);
//Added new
bool exist = Directory.EnumerateFiles(txtSavPath.Text, Path.GetFileNameWithoutExtension(imglst[0]) + "_MSKD*").Any();
if (exist)
{
pnlStatus.BackColor = Color.Red;
}
else
{
pnlStatus.BackColor = Color.Green;
}
}
else
{
MessageBox.Show("SELECT ANOTHER LOCATION", "NO SUPPORTED IMAGES FOUND", MessageBoxButtons.OK);
txtImgNum.Text = "0";
}
}
}
//Function to draw image into picturebox
private void drawImage(string imgList)
{
Bitmap b = new Bitmap(imgList);
image.DrawImage(b, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(btm, Point.Empty);
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
drawing = false;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
drawing = true;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (drawing)
{
c = new SolidBrush(Color.Gray);
image.FillEllipse(c, e.X - (trackBar1.Value / 2), e.Y - (trackBar1.Value / 2), (trackBar1.Value * 15), (trackBar1.Value * 15));
g.DrawImage(btm, Point.Empty);
}
}
private void btnOpen_Click(object sender, EventArgs e)
{
btnNext.Enabled = true;
lblTotl.Text = "#";
var fd = new System.Windows.Forms.FolderBrowserDialog();
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
int i = 0;
txtOpnPath.Text = fd.SelectedPath;
int numImgs = Directory.GetFiles(txtOpnPath.Text, "*.PNG").Length;
imglst = new string[numImgs];
lblTotl.Text = Convert.ToString(numImgs);
foreach (var file in Directory.GetFiles(txtOpnPath.Text, "*.PNG"))
{
imglst[i++] = file;
}
if (imglst.Length > 0)
{
drawImage(imglst[0]);
txtImgNum.Text = "1";
//Added new
bool exist = Directory.EnumerateFiles(txtSavPath.Text, Path.GetFileNameWithoutExtension(imglst[0]) + "_MSKD*").Any();
if (exist)
{
pnlStatus.BackColor = Color.Red;
}
else
{
pnlStatus.BackColor = Color.Green;
}
}
else
{
MessageBox.Show("SELECT ANOTHER LOCATION", "NO SUPPORTED IMAGES FOUND", MessageBoxButtons.OK);
pictureBox1.Image = null;
txtImgNum.Text = "0";
}
using (StreamWriter streamWriter = new StreamWriter("OpenLocation.txt"))
{
streamWriter.WriteLine(txtOpnPath.Text);
}
}
}
private void btnSaveFdr_Click(object sender, EventArgs e)
{
var savFoldr = new System.Windows.Forms.FolderBrowserDialog();
if (savFoldr.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txtSavPath.Text = savFoldr.SelectedPath;
using (StreamWriter streamWriter = new StreamWriter("SaveLocation.txt"))
{
streamWriter.WriteLine(txtSavPath.Text);
}
}
}
private void btnSave_Click(object sender, EventArgs e)
{
saveNxtWasClicked = true;
savePrevWasClicked = true;
int count = 1;
imgCnt = Convert.ToInt32(txtImgNum.Text);
string imgPath = imglst[imgCnt - 1];
string fileName = Path.GetFileNameWithoutExtension(imgPath) + "_MSKD";
string fileExtnsn = Path.GetExtension(imgPath);
string filePath = txtSavPath.Text + "\\" + fileName + fileExtnsn;
while (File.Exists(filePath))
{
string tempFileName = string.Format("{0}({1})", fileName, count++);
filePath = Path.Combine(txtSavPath.Text, tempFileName + fileExtnsn);
}
btm.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
//Writing to CSV
string csvPath = txtCsvPath.Text + "\\CSVSpec.csv";
if (chkbxImageInfo.Checked == true)
{
if (File.Exists(csvPath))
{
// Initialise stream object with file
using (var wr = new StreamWriter(csvPath, true, Encoding.UTF8))
{
// Collection of image details
var row = new List<string>();
row.Add(Path.GetFileNameWithoutExtension(imgPath));
row.Add(txtTestRep.Text);
row.Add(txtBoard.Text);
row.Add(cmbxPosition.Text);
var sb = new StringBuilder();
foreach (string value in row)
{
// Add a comma before each string
if (sb.Length > 0)
{
sb.Append(",");
}
sb.Append(value);
}
wr.WriteLine(sb.ToString());
}
}
else
{
MessageBox.Show("Please add CSVSpec.csv file in specified location to save Image Information.", "MISSING: TEMPLATE FILE", MessageBoxButtons.OK);
}
}
else
{
}
DialogResult result = MessageBox.Show("IMAGE SAVED", "SAVE DIALOGUE", MessageBoxButtons.OK);
if (result == DialogResult.OK)
{
if (imgCnt != imglst.Length)
{
drawImage(imglst[imgCnt]);
imgCnt++;
txtImgNum.Text = Convert.ToString(imgCnt);
txtTestRep.Text = string.Empty;
txtBoard.Text = string.Empty;
cmbxPosition.SelectedIndex = 0;
saveNxtWasClicked = false;
}
else
{
btnNext.Enabled = false;
}
}
}
private void btnPrev_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(txtImgNum.Text);
btnNext.Enabled = true;
if (a > 1)
{
a = a - 2;
drawImage(imglst[a]);
txtImgNum.Text = Convert.ToString(a + 1);
txtTestRep.Text = string.Empty;
txtBoard.Text = string.Empty;
cmbxPosition.SelectedIndex = 0;
bool exist = Directory.EnumerateFiles(txtSavPath.Text, Path.GetFileNameWithoutExtension(imglst[a]) + "_MSKD*").Any();
if (exist)
{
pnlStatus.BackColor = Color.Red;
}
else
{
pnlStatus.BackColor = Color.Green;
}
}
else
{
btnPrev.Enabled = false;
}
}
private void btnNext_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(txtImgNum.Text);
btnPrev.Enabled = true;
if (imglst != null && a < imglst.Length)
{
drawImage(imglst[a++]);
txtImgNum.Text = Convert.ToString(a);
txtTestRep.Text = string.Empty;
txtBoard.Text = string.Empty;
cmbxPosition.SelectedIndex = 0;
bool exist = Directory.EnumerateFiles(txtSavPath.Text, Path.GetFileNameWithoutExtension(imglst[a - 1]) + "_MSKD*").Any();
if (exist)
{
pnlStatus.BackColor = Color.Red;
}
else
{
pnlStatus.BackColor = Color.Green;
}
}
else
{
btnNext.Enabled = false;
}
}
private void txtImgNum_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
int imgNum = Convert.ToInt32(txtImgNum.Text) - 1;
drawImage(imglst[imgNum]);
}
}
private void chkbxImageInfo_CheckedChanged(object sender, EventArgs e)
{
if (chkbxImageInfo.Checked)
{
txtTestRep.Enabled = true;
txtBoard.Enabled = true;
cmbxPosition.Enabled = true;
}
else
{
txtTestRep.Enabled = false;
txtBoard.Enabled = false;
cmbxPosition.Enabled = false;
}
}
private void btnClear_Click(object sender, EventArgs e)
{
int imgNum = Convert.ToInt32(txtImgNum.Text) - 1;
drawImage(imglst[imgNum]);
}
private void btnCsv_Click(object sender, EventArgs e)
{
var csvFoldr = new System.Windows.Forms.FolderBrowserDialog();
if (csvFoldr.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txtCsvPath.Text = csvFoldr.SelectedPath;
using (StreamWriter streamWriter = new StreamWriter("CsvLocation.txt"))
{
streamWriter.WriteLine(txtCsvPath.Text);
}
}
}
}
}
I have 5 buttons and 5 labels next to each button. When i run the app i expect the first button to be enabled and the the rest disabled and greyed out with the labels. after i click the first button it should disable with the label and enable the second button, and so forth with all the other buttons.
this way is to long, is there a better way of doing this?
private void Form1_Load(object sender, EventArgs e)
{
btn1.Enabled = true;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = false;
lblStep1.Enabled = true;
lblStep2.Enabled = false;
lblStep3.Enabled = false;
lblStep4.Enabled = false;
lblStep5.Enabled = false;
}
private void btn1_Click(object sender, EventArgs e)
{
btn1.Enabled = false;
btn2.Enabled = true;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = false;
lblStep1.Enabled = false;
lblStep2.Enabled = true;
lblStep3.Enabled = false;
lblStep4.Enabled = false;
lblStep5.Enabled = false;
}
private void btn2_Click(object sender, EventArgs e)
{
btn1.Enabled = false;
btn2.Enabled = false;
btn3.Enabled = true;
btn4.Enabled = false;
btn5.Enabled = false;
lblStep1.Enabled = false;
lblStep2.Enabled = false;
lblStep3.Enabled = true;
lblStep4.Enabled = false;
lblStep5.Enabled = false;
}
}
private void btn3_Click(object sender, EventArgs e)
{
btn1.Enabled = false;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = true;
btn5.Enabled = false;
lblStep1.Enabled = false;
lblStep2.Enabled = false;
lblStep3.Enabled = false;
lblStep4.Enabled = true;
lblStep5.Enabled = false;
}
private void btn4_Click(object sender, EventArgs e)
{
btn1.Enabled = false;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = true;
lblStep1.Enabled = false;
lblStep2.Enabled = false;
lblStep3.Enabled = false;
lblStep4.Enabled = false;
lblStep5.Enabled = true;
}
private void btn5_Click(object sender, EventArgs e)
{
btn1.Enabled = true;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = false;
lblStep1.Enabled = true;
lblStep2.Enabled = false;
lblStep3.Enabled = false;
lblStep4.Enabled = false;
lblStep5.Enabled = false;
}
Let all these buttons and labels are inside a container(if it doesn't mean that you can use this.Controls as well if the form contains these buttons and labels only). Let it be pnlContainer, Now you can try something like this:
public void ButtonController(Button buttonToEnable, Label labelToenable)
{
foreach (Control ctrl in panel1.Controls)
{
if (ctrl == buttonToEnable || ctrl == labelToenable)
{
ctrl.Enabled = true;
}
else
{
ctrl.Enabled = false;
}
}
}
So in Form1_Load you want to enable btn1 and lblStep1 so the call should be :
ButtonController(btn1,lblStep1);
For btn1_Click the method call will be like ButtonController(btn2,lblStep2);. in short, you can pass the button and label that you want to enable to this method, which will disable rest of controls in the container.
private void txtenable (Boolean txtenable)
{
if(txtenable== false)
{
txtname.Enabled = false;
txtTel.Enabled = false;
txtmobile.Enabled = false;
txtAdress.Enabled = false;
}
else
{
txtname.Enabled = true;
txtTel.Enabled = true;
txtmobile.Enabled = true;
txtAdress.Enabled = true;
}
}
I want use this class but i can not call textboxes. How can call textbox in class?
First you need to be able to accept the TextBox objects within the class, then you can manipulate them how you see fit. I haven't actually tried this, but this is how I would go about setting it up.
public class YourClass
{
TextBox txtName;
TextBox txtTel;
TextBox txtMobile;
TextBox txtAddress;
private void txtenable (Boolean txtenable, TextBox txtName, TextBox txtTel, TextBox txtMobile, TextBox txtAddress)
{
if(txtenable== false)
{
txtName.Enabled = false;
txtTel.Enabled = false;
txtMobile.Enabled = false;
txtAddress.Enabled = false;
}
else
{
txtName.Enabled = true;
txtTel.Enabled = true;
txtMobile.Enabled = true;
txtAddress.Enabled = true;
}
}
In order for you to access the textboxes from within your class you will need to pass them such as:
public class OtherClassContainingTextBoxes
{
private void SomeEvent(object sender, EventArgs e){
txtenable(true, txtName, txtTel, txtMobile, txtAddress);
}
However, based on the example provided, I am unsure why you wouldn't do this in a method within the class you have your textboxes.
You could do something on pageload:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["enable"] == false){
txtenable(false);
}else{
txtenable(true);
}
}
private void txtenable (Boolean txtenable)
{
if(txtenable== false)
{
txtName.Enabled = false;
txtTel.Enabled = false;
txtMobile.Enabled = false;
txtAddress.Enabled = false;
}
else
{
txtName.Enabled = true;
txtTel.Enabled = true;
txtMobile.Enabled = true;
txtAddress.Enabled = true;
}
}
I am selecting a row from Gridview, working good except for checkbox, like I am assigning value of checkbox retreived from gridview to checkbox that is placed on web form but it isn't represented by checkbox on form, it shows empty checkbox in every case
if (gridviewDesignations.SelectedRow.Cells[5].Text == " ")
{
chkIsHead.Text = gridviewDesignations.SelectedRow.Cells[5].Text;
}
in short, checkbox is not picking value from gridview
Update:
tried this too:
CheckBox chkIsHead = (CheckBox) gridviewDesignations.SelectedRow.Cells[5].Controls[0];
if (chkIsHead.Checked == false)
{
chkIsHead.Checked = false;
}
else
{
chkIsHead.Checked = true;
}
Update:
my full code:
public partial class frmDesignations : System.Web.UI.Page
{
AccessibleVariables accessVariables = new AccessibleVariables(); //Used to access global variables
public void Clear(params TextBox[] txtBoxes)
{
foreach (TextBox txtbx in txtBoxes)
{
txtbx.Text = "";
}
}
public void fillddlDepartments()
{
ManageDepartmentsBizz mngDepBizz = new ManageDepartmentsBizz();
DataSet ds = (DataSet)mngDepBizz.SelectDepartments();
if (ds.Tables[0].Rows.Count != 0)
{
ddlDepartments.DataValueField = "DepID";
ddlDepartments.DataTextField = "DepName";
ddlDepartments.DataSource = ds.Tables[0];
// ddlDepartments.SelectedIndex = -1;
ddlDepartments.DataBind();
ddlDepartments.Items.Insert(0, "--Select--");
}
//else
// ddlDepartments.SelectedIndex = -1;
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session.Count <= 0)
{
Response.Redirect("login.aspx");
}
lblMsgPopUp.Visible = false;
if (!IsPostBack)
{
fillddlDepartments();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
int DepartmentID = Convert.ToInt32(ddlDepartments.SelectedValue);
bool IsHead = Convert.ToBoolean(chkIsHead.Checked);
DesignationsBizz DesigBizz = new DesignationsBizz(-1, txtTitle.Text, DepartmentID, txtContactNo.Text, IsHead);
//-1 is bogus,used to fill parameters criteria i.e no of params
ManageDesignationsBizz mngDesigBizz = new ManageDesignationsBizz();
bool Result = mngDesigBizz.Insert(DesigBizz);
if (Result == true)
{
HiddenFieldSetMessage.Value = "Saved";
HiddenFieldShowMessage.Value = "True";
Clear(txtTitle, txtSelectedID, txtContactNo);
}
else
{
HiddenFieldSetMessage.Value = "RecordAlreadyExists";
HiddenFieldShowMessage.Value = "True";
}
}
catch (Exception)
{
HiddenFieldSetMessage.Value = "NotSaved";
HiddenFieldShowMessage.Value = "True";
}
}
protected void btnSearchPopup_Click(object sender, EventArgs e)
{
string DesignationTitle = txtDesignationPopUp.Text;
ManageDesignationsBizz mngDepsBizz = new ManageDesignationsBizz();
DataSet ds = (DataSet)mngDepsBizz.Select(DesignationTitle);
if (ds.Tables[0].Rows.Count != 0)
{
lblMsgPopUp.Visible = false;
gridviewDesignations.DataSource = ds.Tables[0];
gridviewDesignations.DataBind();
gridviewDesignations.Visible = true;
}
else
{
lblMsgPopUp.Visible = true;
gridviewDesignations.Visible = false;
}
}
protected void gridviewDesignations_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
string DesignationTitle = txtDesignationPopUp.Text;
ManageDesignationsBizz mngDepBizz = new ManageDesignationsBizz();
DataSet ds = (DataSet)mngDepBizz.Select(DesignationTitle);
if (ds.Tables[0].Rows.Count != 0)
{
gridviewDesignations.PageIndex = e.NewPageIndex;
gridviewDesignations.DataSource = ds.Tables[0];
gridviewDesignations.DataBind();
gridviewDesignations.Visible = true;
}
}
protected void btnEdit_Click(object sender, EventArgs e)
{
if (gridviewDesignations.SelectedRow != null)
{
if (gridviewDesignations.SelectedRow.Cells[1].Text == " ")
{
txtSelectedID.Text = string.Empty;
}
else
{
txtSelectedID.Text = gridviewDesignations.SelectedRow.Cells[1].Text;
}
if (gridviewDesignations.SelectedRow.Cells[2].Text == " ")
{
txtTitle.Text = string.Empty;
}
else
{
txtTitle.Text = gridviewDesignations.SelectedRow.Cells[2].Text;
}
if (gridviewDesignations.SelectedRow.Cells[3].Text == " ")
{
ddlDepartments.SelectedValue = string.Empty;
}
else
{
ddlDepartments.SelectedValue = gridviewDesignations.SelectedRow.Cells[3].Text;
accessVariables.DepID = Convert.ToInt32(gridviewDesignations.SelectedRow.Cells[3].Text);
ViewState["depID"] = accessVariables.DepID;
}
if (gridviewDesignations.SelectedRow.Cells[4].Text == " ")
{
txtContactNo.Text = string.Empty;
}
else
{
txtContactNo.Text = gridviewDesignations.SelectedRow.Cells[4].Text;
}
CheckBox chkIsHead = (CheckBox) gridviewDesignations.SelectedRow.Cells[5].Controls[0];
if (chkIsHead.Checked == false)
{
chkIsHead.Checked = false;
}
else
{
chkIsHead.Checked = true;
}
gridviewDesignations.DataBind();
gridviewDesignations.SelectedIndex = -1;
HiddenFieldShowHideButtons.Value = "True";
}
}
protected void btnUpdatePopUp_Click(object sender, EventArgs e)
{
try
{
int id = Convert.ToInt32(txtSelectedID.Text);
int DepartmentID = Convert.ToInt32(ddlDepartments.SelectedValue);
bool IsHead = Convert.ToBoolean(chkIsHead.Checked);
DesignationsBizz DesigBizz = new DesignationsBizz(id, txtTitle.Text, DepartmentID, txtContactNo.Text, IsHead );
ManageDesignationsBizz mngDesigBizz = new ManageDesignationsBizz();
bool Result = mngDesigBizz.Update(DesigBizz);
if (Result == true)
{
HiddenFieldSetMessage.Value = "Updated";
HiddenFieldShowMessage.Value = "True";
Clear(txtSelectedID, txtTitle, txtContactNo);
}
else
{
HiddenFieldSetMessage.Value = "NotUpdated";
HiddenFieldShowMessage.Value = "True";
}
}
catch (Exception)
{
HiddenFieldSetMessage.Value = "NotUpdated";
HiddenFieldShowMessage.Value = "True";
}
}
protected void btnDeletePopUp_Click(object sender, EventArgs e)
{
try
{
int ID = Convert.ToInt32(txtSelectedID.Text.Trim());
ManageDesignationsBizz mngDepBizz = new ManageDesignationsBizz();
mngDepBizz.Delete(ID);
Clear(txtTitle, txtSelectedID, txtContactNo);
HiddenFieldSetMessage.Value = "Deleted";
HiddenFieldShowMessage.Value = "True";
}
catch (Exception)
{
HiddenFieldSetMessage.Value = "NotDeleted";
HiddenFieldShowMessage.Value = "True";
}
}
protected void btnClosePopup_Click(object sender, EventArgs e)
{
Clear(txtTitle, txtSelectedID, txtContactNo);
}
protected void ddlDepartments_SelectedIndexChanged(object sender, EventArgs e)
{
if (txtSelectedID.Text != "")
{
accessVariables.DepID = Convert.ToInt32(ddlDepartments.SelectedValue);
ViewState["depID"] = accessVariables.DepID;
}
else
{
accessVariables.DepID = Convert.ToInt32(ddlDepartments.SelectedValue);
ViewState["depID"] = accessVariables.DepID;
}
}
protected void chkIsHead_CheckedChanged(object sender, EventArgs e)
{
if (txtSelectedID.Text != "")
{
int DepID = Convert.ToInt32(ViewState["depID"]);
ManageDesignationsBizz mngDesig = new ManageDesignationsBizz();
bool isHead = mngDesig.SelectIsHeadExistsByDepID(DepID);
if (isHead == true)
{
HiddenFieldSetMessage.Value = "HeadExists";
HiddenFieldShowMessage.Value = "True";
chkIsHead.Checked = false;
}
}
else
{
int DepID = Convert.ToInt32(ViewState["depID"]);
ManageDesignationsBizz mngDesig = new ManageDesignationsBizz();
bool isHead = mngDesig.SelectIsHeadExistsByDepID(DepID);
if (isHead == true)
{
HiddenFieldSetMessage.Value = "HeadExists";
HiddenFieldShowMessage.Value = "True";
chkIsHead.Checked = false;
}
}
}
}
I believe the following is what you need to do:
Then select EditProgrammatically.
I'm not sure if yoou'll need to manually put data into the grid though but that won't be too hard. Examples can be seen here : http://msdn.microsoft.com/en-us/library/system.data.datatable(v=vs.110).aspx
PS : You can set the DataSource in the grid view to the DataTable.
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...
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)
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
{
public 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.