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.
Related
I'm trying to create an Update button to let me insert data into a gridview and after creating the class, the button does nothing and I don't understand why that is the case.
private void Basic()
{
// no updates allowed
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.ReadOnly = true;
//UpdateButton is available
UpdateButton.Enabled = true;
//Save and Cancel Unavailable
SaveButton.Visible = false;
CancelButton.Visible = false;
sTableAdapter.Fill(dataSet1.S);
}
This is the UpdateButton Event
private void UpdateButton_Click(Object sender, EventArgs e)
{
dataGridView1.AllowUserToAddRows = true;
dataGridView1.AllowUserToDeleteRows = true;
dataGridView1.ReadOnly = false;
UpdateButton.Enabled = false;
SaveButton.Visible = true;
CancelButton.Visible = true;
}
And this should be the update class:
this.UpdateButton.Location = new System.Drawing.Point(12, 63);
this.UpdateButton.Name = "UpdateButton";
this.UpdateButton.Size = new System.Drawing.Size(103, 23);
this.UpdateButton.TabIndex = 0;
this.UpdateButton.Text = "Update";
this.UpdateButton.UseVisualStyleBackColor = true;
The connection is made with a accdb.
The Update button isn't working on click, what did I do wrong?
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;
}
}
please i need a help i'm writing a code for hangman game and i want just to change the icon of the form , i try that using the icon property but it doesn't work any more ,please how i can do this ,and also i do the following project-->properties--->icon and manifest but also it doesn't work this is my code for the game it work perfectly :
private void button1_Click(object sender, EventArgs e)
{
stage_count++;//strat from stage 1
if (!int.TryParse(textBox1.Text.ToString(), out value))
return;//if user inter non_integer value do no thing and wait for new entry
if (key ==value )//directly if user guesses the key he/she wins the game
{
//view the seventh picture in hangman game
button1.Enabled = false;
textBox1.Text = "";
textBox1.Enabled = false;
pictureBox7.Visible = true;
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
groupBox1.Visible = true;
label1.Text = "Great... You Got It ^_^ ";
}
if (key > value)//guide the user to the correct answer
label1.Text = "Should Be Greater than" + value.ToString();
if (key < value)//guide the user to the correct answer
label1.Text = "Should Be Less than" + value.ToString();
if (key != value)
{
switch (stage_count)
{//this switch statement used to do some thing in each stage
case 1:
//view the first picture in hangman game
pictureBox1.Visible = true;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
break;
case 2:
//view the second picture in hangman game
pictureBox1.Visible = false;
pictureBox2.Visible = true;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
break;
case 3:
//view the third picture in hangman game
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = true;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
break;
case 4:
//view the fourth picture in hangman game
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = true;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
break;
case 5:
//view the fifth picture in hangman game
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = true;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
break;
default:
//view the sixth picture in hangman game
//it's the last try so diable the button and show the result
button1.Enabled = false;
textBox1.Text = "";
textBox1.Enabled = false;
groupBox1.Visible = true;
label1.Text = "YOU LOSE ,, IT WAS : " + key.ToString();
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = true;
pictureBox7.Visible = false;
break;
}//end switch
//to make empty focused textbox
textBox1.Text = "";
textBox1.Focus();
}//end if
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{// if user want to playe new game the programm must enables the important controls and
//make the visible property equals to false for all the pictures boxes
if (radioButton1.Checked == true)
{
stage_count = 0;
key = (1 + obj.Next(99));
textBox1.Enabled = true;
textBox1.Text = "";
textBox1.Focus();
button1.Enabled = true;
label1.Text = "Guess a number btween 1-100";
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
groupBox1.Visible = false;
radioButton1.Checked = false;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
// if user won't to play again just close it
if (radioButton2.Checked == true)
{
radioButton2.Checked = false;
this.Close();
}
}
}
}
GO Properties window and change "Icon" property with your own icon.
You need to perform following steps
Add you icon to resouce file of project
than Asssing the created resource to you icon property .
Icon = Resources.adobe_reader_icon;
You have to set it in the properties of your project.
If you start your application by pressing F5 in VisualStudio and the icon doesn't appear, take a look in the Debug-(Release) Directory. There should be the correct icon
The icon of a form is only displayed if:
- ControlBox is true
- FormBorderStyle is not None
- Text is not empty
If so, you should then be able to set it with this.Icon = ...
Also the icon should be available as project resource. For this, you can just edit the forms Icon property, and in the following dialog import the icon from a .ico file.
<pre>
application root directory
application resources directory **LIKE** ../../resources/dropbox.ico
this.Icon = new System.Drawing.Icon("../../dropbox.ico");
</pre>
First Solution then Properties of the project Add .ico file
Then open Form which you want icon
In Form property you can find Icon Field
There you can change Icon your windows form.
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.
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.