how to open usercontrol and close 2 seconds [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
Hello People how can i open userControl and close in the 2 seconds and show another form?
c# WinForms

public void MyFunction()
{
firstForm.ShowDialog();
secondForm.Show();
}
public void firstForm_Load(object sender, EventArgs e)
{
Timer timer = new System.Windows.Forms.Timer() { Interval = 2000 };
timer.Tick += delegate { timer.Stop(); Close(); };
timer.Start();
}

Related

Finally and c# reference types [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am not able to figure how will this work:
public Class1 Function1()
{
DataTable dt;
try
{
dt = new DataTable();
//.. Do some work
return new Class2(byref dt);
}
finally
{
dt.dispose();
}
}
public Class2(byref DataTable dTable)
{
this.dataTable = dTable;
}
So, now if I say Class1 obj1 = Function1(); will my obj1.dataTable be disposed? or it will have proper data?
yes assuming obj1.dataTable refers to the same object you created inside Function1, it will have been disposed. Finally blocks are always executed, regardless of whether an exception is thrown or not.
Here's some more information on try-finally blocks.

Using ProgressBar for specific time [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want my ProgressBar starting in some point in my code and run total of seconds until my file finish, and of course I know how long the run of my file will take.
I try to read on MSDN but I did not understood how to use it.
My application run files (wireshark file, send the packet using bittwist) and each file will run few seconds and I want the option to see the progress ongoing.
For example I want to set my ProgressBar running for 30 seconds.
How can I do it?
Maybe you want something like this:
public void AnimateProgBar (int milliSeconds)
{
if (!timer1.Enabled) {
progressBar1.Value = 0;
timer1.Interval = milliSeconds / 100;
timer1.Enabled = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < 100) {
progressBar1.Value += 1;
progressBar1.Refresh();
} else {
timer1.Enabled = false;
}
}
Then you just have to call AnimateProgBar(2000) to have your ProgressBar animated during 2 seconds.
EDIT: Sorry, I posted code in VB.NET. Modified to C#.
EDIT: You can add the handler and call the function in this way (for example):
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
AnimateProgBar(2000);
}

C# integer variable in foreach loop [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
In C# I have a foreach loop where I want to ++ a integer.
The code is like this:
private void btnClick(object sender, EventArgs e)
{
int Counter = 0;
foreach (SettingsProperty currrentProperty in Properties.Settings.Default.Properties)
{
Counter++;
}
lblText.Text = Counter.ToString();
}
Simple, but of course because I have to assing the integer the variable sticks to 0, otherwise the compiler errors. So the lblText.Text prints 0 to me.
I just can't get it working properly..
Sure this is an easy one, but I couldn't find a awnser.
I think that Properties.Settings.Default.Properties is empty . So to get sure that it is empty try:
private void btnClick(object sender, EventArgs e)
{
if(Properties.Settings.Default.Properties.Count != 0)
{
int Counter = 0;
foreach (SettingsProperty currrentProperty in Properties.Settings.Default.Properties)
{
Counter++;
//Some stuff here else just use .Count without use a foreach
}
lblText.Text = Counter.ToString();
}
else
throw new Exception("Properties.Settings.Default.Properties is empty");
}
Else try to set some breakpoints before compile the code.

Need an equivalent for a C# code in VB.Net [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm doing C# And now I want to learn about VB.Net, and I want the equivalent for this:
Hide();
using (login loginForm = new login())
{
var result = loginForm.ShowDialog();
if (result == DialogResult.OK)
{
Show();
}
else
{
Close();
}
}
Hide()
Using loginForm As New login()
Dim result = loginForm.ShowDialog()
If result = DialogResult.OK Then
Show()
Else
Close()
End If
End Using
What did you try yourself? Just look up each thing on MSDN (Using statement, If statement, ...) and look at the code examples in VB.
Anyway, here is the converted code:
Hide()
Using loginForm As New login()
Dim result = loginForm.ShowDialog()
If result = DialogResult.OK Then
Show()
Else
Close()
End If
End Using

How can I prevent a ListView option from changing? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How can I prevent a ListView option from changing?
I have tried the following, however it still changes:
bool q=false;
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (q)
{
// Let change happen
}
else
{
// Stop change from happening
return;
}
}
Thank you for any help.
Save the prior value and then reset it to the prior.
int lastIndex = -1;
if (q)
{
lastIndex = (ListView)Sender.SelectedIndex;
}
else
{
// Stop change from happening
(ListView)Sender.SelectedIndex = lastIndex;
}

Categories