Relate control to working events - c#

I have .net win form application , its a pretty big application , first i was using .Net original controls , than i switched to Telerik and deleted the old control and create new button , checkes etc with same name and than due to some problem reverted back to original
.Net controls ,
i have more than 200 controls , and all my code look like this , its so mess , is there any easy way that i can relate only working event to my control with removing _1 , _2 , _3
mean is there any automated way ?
using vs 2012 and .net 4
private void chkPk_CheckedChanged_1(object sender, EventArgs e)
{
// Code
}
private void chkPk_CheckedChanged_2(object sender, EventArgs e)
{
// Code
}
private void chkPk_CheckedChanged_3(object sender, EventArgs e)
{
// Code
}

Maybe it's about addhandler
this.chkPk_1.CheckedChanged += new System.EventHandler(this.myEventHandler);
this.chkPk_2.CheckedChanged += new System.EventHandler(this.myEventHandler);
private void myEventHandler(object sender, EventArgs e)
{
// Code
}
See the reference .. http://msdn.microsoft.com/en-us/library/aa984308(v=vs.71).aspx

Related

Panel Drag and Drop not working in winForms Application

I am developing a winForm application using c#.NET. On the form i have placed a panel, and i have 2 methods :
private void panel1_DragDrop(object sender, DragEventArgs e){
//some code here
}
private void panel1_DoubleClick(object sender, EventArgs e){
//some code here
}
Whenever i run the program in debug mode(x64), i cannot seem to hit panel1_DragDrop method. I have also tried using a breakpoint , but it is also not being hit.
I have put property AllowDrop=true for this panel, but still nothing is happening.
What could be the possible reason?
Did you tried DragEnter event :
private void panel1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (Path.GetExtension(files[0]).ToLower() == ".pdf")//jpg,bmp,docx,....
{
//Code
}
}
Also please check if your application isn't running as another user privilege like Run as Administrator.
"Run as Administrator" prevents drag and drop working.

Bring custom control to front

I recently started to learn C# and right now I want to mess arouwnd with the Form[Design].
Right now I'm trying to BringToFront() custom controls each time I hover over a button (Ive got a few buttons close to each other, each time I hover over them I get a certain User Control).
This is what I've got so far:
private void button1_Hover(object sender, EventArgs e)
{
costumControl1.BringToFront();
}
private void button1_Leave(object sender, EventArgs e)
{
CostumControl0.BringToFront();
}
private void button2_Hover(object sender, EventArgs e)
{
costumControl2.BringToFront();
}
private void button2_Leave(object sender, EventArgs e)
{
CostumControl0.BringToFront();
}
private void button3_Hover(object sender, EventArgs e)
{
costumControl3.BringToFront();
}
private void button3_Leave(object sender, EventArgs e)
{
CostumControl0.BringToFront();
}
But bringing to front the user control costumControl0 when I hover from a button to another it's not what I want.
But I don't know how to go about this.
Is it possible to just add a if statement where I check if I'm not hovering the buttons close to my current one and then display the costumControl0.
Or a timer is necessary to delay the display of the costumControl0 and skip the command if I'm starting another event.
If the timer is needed, can I use one timer for all of the buttons or do I need to create one for each?
Or whats the best approach for this?

visual studio C# combo box event

private void droplesson_SelectedIndexChanged(object sender, EventArgs e)
{
if(e.Equals("LESSON1"));
reload("LESSON1.txt");
if(e.Equals("LESSSON2"));
reload("LESSON2.txt");
if(e.Equals("LESSON3"));
reload("LESSON3.txt");
if(e.Equals("LESSON4"));
reload("LESSON4.txt");
if (e.Equals("LESSON5"));
reload("LESSON5.txt");
}
Above code is not working. I want to change the dropdown menu such that when i select the particular lesson it reload that lesson.enter image description here
You added ';' at the end of every line, including the 'if' lines, soo all of the 'reload' calls got executed...
This is how your code should look:
private void droplesson_SelectedIndexChanged(object sender, EventArgs e)
{
if(e.Equals("LESSON1"))
reload("LESSON1.txt");
if(e.Equals("LESSSON2"))
reload("LESSON2.txt");
if(e.Equals("LESSON3"))
reload("LESSON3.txt");
if(e.Equals("LESSON4"))
reload("LESSON4.txt");
if (e.Equals("LESSON5"))
reload("LESSON5.txt");
}

How do I redirect a checkbox to another page in my app if checked Xamarin Android C#?

I am making an android app using C# in Xamarin studio. I managed to make the checkboxes and among other things. I need to know what code I would need to use make a the checkbox go to redirect to another page if checked. I am new to programming so I am sure this is an easy question but I am having trouble.
This is what you need to do
private void MainPage_Load(object sender, EventArgs e)
{
checkBox1.CheckedChanged += checkBox1_CheckedChanged;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
// your code to go to the other page.
}
}

C# Tabless Control Previous/Back/Return Button failing?

I am hoping someone here can help me, i have a Tabless Control on my windows forms application and basically because the tabs are purposely hidden i have added 2 buttons to each tab "Next" and "Back".
This is the code snippet i have for my "Next" button:
private void nextbutton1_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage3;
this.toolStripStatusLabel8.Text = System.DateTime.Now.ToString();
}
Which works fine, however when i use the exact same theory on the "Back" button it does not work:
private void backbutton1_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabmain;
this.toolStripStatusLabel1.Text = System.DateTime.Now.ToString();
}
So my question is how does one go to a previous tabpage from a button? I have looked through here and tried all of the links that came up but nothing has worked any ideas?
You should use the SelectedIndex property instead of using concrete TabPage instances. This way it will still work when you decide to change the order of the pab pages or add new pages:
private void previousButton_Click(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex > 0)
{
tabControl1.SelectedIndex--;
}
}
private void nextButton_Click(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex < tabControl1.TabCount - 1)
{
tabControl1.SelectedIndex++;
}
}
Since there is no "Tabless" tab control in .NET Framework I can only assume that it works similar to the standard TabControl. If the solution doesn't work you should give us some information about the actual class you use.
BTW: There is no need to repeat the buttons on each page. Why don't you just put the buttons outside the TabControl?
Also: I see that you use a ToolStripStatusLabel to show the current time. Instead of updating it each time the user clicks somewhere add a Timer to your form. Set its Interval to 1000 and handle its Tick event. Update the label there:
private void timer1_Tick(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = DateTime.Now.ToLongTimeString();
}
This way it updates constantly and again there is no need to repeat anything. You need to call timer1.Start() in the form's constructor.

Categories

Resources