organized workingspace in c# form - c#

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.

Related

How to hide and show a panel by clicking a button in C#

I have three panels and three buttons. Upon clicking button1 I want to show Panel1 and hide Panel2 and Panel3.
The same process with the other buttons and panels. How can I do this?
I'm using a Window Forms application written in C#/.NET. This code is not working very well, because only two panels are showing.
private void frmMain_Load(object sender, EventArgs e)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
private void btnItems_Click(object sender, EventArgs e)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
private void btnCustomers_Click(object sender, EventArgs e)
{
pnlCustomer.Visible = true;
pnlItems.Visible = false;
pnlPOS.Visible = false;
}
private void btnPOS_Click(object sender, EventArgs e)
{
pnlPOS.Visible = true;
pnlCustomer.Visible = false;
pnlItems.Visible = false;
}
private void frmMain_Load(object sender, EventArgs e)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
private void btnItems_Click(object sender, EventArgs e)
{
if(pnlItems.Visible != true)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
}
private void btnCustomers_Click(object sender, EventArgs e)
{
if(pnlCustomer.Visible != true)
{
pnlCustomer.Visible = true;
pnlItems.Visible = false;
pnlPOS.Visible = false;
}
}
private void btnPOS_Click(object sender, EventArgs e)
{
if(pnlPOS.Visible != true)
{
pnlPOS.Visible = true;
pnlCustomer.Visible = false;
pnlItems.Visible = false;
}
}
Here I have updated the conditional statement for if your panel is not visible then act. I hope this will work.

Update button for GridView

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?

Enable and Disable buttons, labels based on some conditions

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.

how can disable a textbox in class asp.net

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;
}
}

shivery effect of the GUI prepared using C# windows forms

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.

Categories

Resources