Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DrawString MDI Form
Message
De
30/01/2012 12:53:16
 
 
À
29/01/2012 17:50:29
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01533626
Message ID:
01534093
Vues:
36
>>If TestDrawMyText() is being called by Paint() aren't you going to have quite a few handlers hooked up to the MouseMove :-}
>
>Of course Viv ... you are correct (as usual). I think I missed the point in Pete's original question that he was calling this from the Paint(). So yeah, in this case, an anonymous delegate would NOT be a good idea. Thanks for calling me out on that one! Oh dopey me!! <g>

I was just sort of teasin' - I know that if you had remembered the context you would not have suggested it (and that, likewise, Mr. Kane would have spotted the same thing...)


>
>~~Bonnie
>
>>>First, you'll have to use the MouseMove event. There is no MouseOver event and the MouseHover event does not use MouseEventArgs, which you'll need. You can actually do it two different ways, one of which won't require you to save x,y and size.
>>>
>>>1) If you *do* save x,y and s (size), then you can determine in the MouseMove event handler whether you're in the area like this:
>>>
>>>
>>>private void Form1_MouseMove(object sender, MouseEventArgs e)
>>>{
>>>    if (e.X >= x && e.X <= x + s.Width && e.Y >= y && e.Y <= y + s.Height)
>>>        Console.WriteLine("Mouse At {0},{1}", e.X, e.Y);
>>>}
>>>
>>>
>>>You can also take care of the whole thing right in your DrawMyText() using anonymous delegates. By doing it this way, you won't even have to save x, y and s!!
>>>
>>>
>>>private void TestDrawMyText(Graphics g, string MyText)
>>>{
>>>	SizeF s = g.MeasureString(MyText, MyFont);
>>>	float x = this.Width / 2 - s.Width / 2;
>>>	float y = this.Height / 2 - s.Height / 2;
>>>	g.DrawString(MyText, MyFont, Brushes.Gold, x, y, StringFormat.GenericTypographic);
>>>
>>>	this.MouseMove += delegate(object sender, MouseEventArgs e)
>>>	{
>>>		if (e.X >= x && e.X <= x + s.Width && e.Y >= y && e.Y <= y + s.Height)
>>>			Console.WriteLine("Mouse in TextArea At {0},{1}", e.X, e.Y);
>>>	};
>>>}
>>>
>>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform