|
|
Completely new to C#.
can anyone give me a big picture on how Timer works in C#?
For example, what is the framework for me to do a certain job, say methodX(), every 5 seconds?
thanks in advance!
|
|
|
|
|
Timers are really simple to use in C#.
All you have to do is declare a timer:
private System.Windows.Forms.Timer timer1; or drag it onto your form.
Setup the interval and add a message handler:
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
private void timer1_Tick(object sender, System.EventArgs e)
{
// add your code here. right now tis fucntion will get called once every second.
}
Hope this helps.
|
|
|
|
|
Good morming gurus,
Do you know a good source on how to alternate color on every other items of list box or combo box?
Thanks so much
Khang Nguyen
|
|
|
|
|
This is what I did in a listview control. The code below changes every other row to a different back color.
private void ColorRow()
{
if( m_bListViewBackColor )
{
m_bListViewBackColor = false;
}
else
{
m_bListViewBackColor = true;
}
ListViewItem Lvi;
// Add a listitem
Lvi = m_ListView.Items.Add( 1 );
Lvi.SubItems.Add( "John" );
Lvi.SubItems.Add( "Smith" );
if( m_bListViewBackColor )
{
Lvi.BackColor = Color.Crimson;
}
else
{
m_bListViewBackColor = false;
Lvi.BackColor = Color.White;
}
}
Declare m_bListViewBackColor at the top of your app.
This isn't exactly what you're looking for, but I think it should get you headed in the right direction.
|
|
|
|
|
Thank you very much for the tip, Manster!
Khang Nguyen
|
|
|
|
|
Hi !
I'd like to implement basic image processing like gamma, brightness and contrast.
I found on codeproject an excellent article by Christian Graus on image processing with GDI+.
Problem is that method is very slow. I compare it with Microsoft Photo Editor (included with MS Word) and it's much faster.
Maybe my method isn't the best one:
On Filter Attribut Changed:
Bitmap b = m_OriginalImage.Clone();
Filters.Brightness(b, BrightnessAttribut);
Filters.Contrast(b, ContrastAttribut);
Filters.Gamma(b, GammaAttribut);
pictureBox.Image = b;
End
Help's appreciate.
Thanks
--
aer@s
|
|
|
|
|
Does anybody know how show "welcome" dialog while the the rest of the application is being loaded (C#)?
Thanks a lot,
Andrey
|
|
|
|
|
here is what im using in my apps:
AboutBox myAboutBox = new AboutBox();
myAboutBox.Show();
myAboutBox.Refresh();
Thread.Sleep(1500);
InitializeComponent();
myAboutBox.Hide();
myAboutBox.Dispose();
i find that you need to call the Refresh() before doing anything cpu intensive or it might not show cause its too busy processing other stuff..
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
If you do a Thread.Sleep the rest of the application will not be loaded. Why don't you try something like that
<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
....<br />
Form2 frm= new Form2();<br />
public Form1()<br />
{<br />
Thread thread = new Thread(new ThreadStart(StartForm2));<br />
thread.Start();<br />
frm.Close();<br />
}<br />
<br />
private void StartForm2()<br />
{<br />
if (frm != null)<br />
frm.ShowDialog();<br />
<br />
}<br />
....<br />
}<br />
|
|
|
|
|
if you look back at my code you'll see that the Thread.Sleep(1500) is just to pause for a second.. i know nothing is going to happen during that time..
right above that is where i load all of my stuff.. i just pause so that the splash screen is showed for at least a second, it serves no other purpose and can be removed. this is all in my constructor for my main form..
what is the benefit of creating a thread just to show and close the dialog when you could just show and hide the dialog around the section of code that does your loading?
AboutBox myAboutBox = new AboutBox();
myAboutBox.Show();
myAboutBox.Refresh();
Thread.Sleep(1500);
InitializeComponent();
myAboutBox.Hide();
myAboutBox.Dispose();
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
I'm sorry if I'm offended you I didn't want to criticize your code.
What I'm saying is if that guy wants to show a form during the load of the real application, in my opinion is better to show it in a different thread because it guarantees that the form will be shown and you will not get a blank screen because the application is busy doing other things. But of course you can also use tricks like Refresh() or Application.DoEvents() doesn't matter.
|
|
|
|
|
ah.. i was wondering why i had to refresh the form to make it show.. i guess i can see how having another thread could help them both.. especially if you wanted your loading form to have some sort of animation or something.. btw, i wasnt offended, i honestly wanted to know the purpose
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
Thanks guys for your replies.
Jose, when I try to close the "start" form, the main form losts focus. Any ideas how to dial with that?
------------------------
Andrey
|
|
|
|
|
my guess is that if you just called Focus() it would get focus back
Form1.Focus();
thats my guess
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
i have a listbox and a button.. when you click on the button i want to remove what is selected in the listbox, but i need to be able to tell if something is selected in the box or not..
if (this.lvSDeduc.SelectedItems == null)
{ MessageBox.Show("You must select something to remove before clicking the remove button.");
return; }
ListViewItem objItem = this.lvSDeduc.SelectedItems[0]; this doesnt work, so when it gets to the SelectedItems[0] i crash since there is nothing selected.. any suggestions?
thanks in advance!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
use this code
if (this.lvSDeduc.SelectedItems.count == 0)
{ MessageBox.Show("You must select something to remove before clicking the remove button.");
return;
}ListViewItem objItem = this.lvSDeduc.SelectedItems[0];
i think it will work
From Greece:
Dimitris Iliopoulos
dimilio@yahoo.com
|
|
|
|
|
doh, should have thought of that one thanks a ton!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
Try this in your button message handler:
string sSelectedItem = m_ListBox.SelectedItem.ToString();
if( sSelectedItem != null )
{
m_ListBox.Items.Remove( sSelectedItem );
}
Hope this helps
|
|
|
|
|
does anyone know how to prevent that "do you wish to send this mail?" dialog that appears when sending documents via crystal reports??
//Roger
|
|
|
|
|
Something kind of puzzled me quite a while ago and has came back up again (just like eating KFC Chicken, taste that stuff for three days). Why exactly does it matter to declare a delegate outside a class definition instead of just declaring it inside the class?
Rocky Moore <><
|
|
|
|
|
Well, a delegate is a class. So, if you declare a delegate DelegateType inside a class ClassType, you will have to reference it via ClassType.DelegateType instead of just DelegateType, if you are referring to it from outside the class.
|
|
|
|
|
Yes, that is the obvious, since it is nested it must be referenced with the class it is defined in. Is that the only reason though? That is the actual results I like, since it pertains to the class I like have it contained in the class.
Rocky Moore <><
|
|
|
|
|
Rocky Moore wrote:
That is the actual results I like, since it pertains to the class I like have it contained in the class.
And you can mark it internal etc to hide to implementation. Personally I keep delegates outside types, but mark them internal.
<a TITLE="See my user info" href=http:
|
|
|
|
|
I’m trying to scrape a site but I’m having a problem.
My program works for 4 iterations and then stops. I ported this code, line for line, over to Perl and it works fine.
I stepped through the C# code and found that it hangs on this line:
objStream = wrGETURL.GetResponse().GetResponseStream();
But it only hangs on the fifth time, it works for the first four times.
This is baffling me, so I'm hoping one of you guys can figure out what is wrong.
e") != -1)ThisOne = true;
}
}
Console.ReadLine();
}
}
}
|
|
|
|