|
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics gfx = e.Graphics;
gfx.DrawString("135", new Font("Freestyle Script",
40f, FontStyle.Bold),
new SolidBrush(Color.Red),
new Point(20,20));
How would you know when the mouse cursor is inside a rectangle area of the above drawn text??
|
|
|
|
|
well.. You need to trap mousemove to get the cursor position.
check value of EventArgs that comes along with the Event Delegate.
|
|
|
|
|
Hi,
there is a sibbling method called MeasureString, when used correctly it provides information about the size a DrawString is going to take. However there are minor deviations, there even is a CP article on that subject.
I expect most text processors (when using a proportional font) would draw only one word at a time, and store all the coordinates; so you would need MeasureString only inside a word, and visual feedback with a caret sufficiently solves inaccuracies.
BTW: the few lines of code you have shown are horrible for performance and memory, as they create new objects (Font, Brush) for every Paint, and don't Dispose of them.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Thanks Luc, Actually I know about the measureString thing but wanted to hear your opinions.. And don't worry, I just posted the shortest segment I can to show my problem
|
|
|
|
|
Luc Pattyn wrote: there is a sibbling method called MeasureString, when used correctly it provides information about the size a DrawString is going to take. However there are minor deviations, there even is a CP article on that subject.
I expect most text processors (when using a proportional font) would draw only one word at a time, and store all the coordinates; so you would need MeasureString only inside a word, and visual feedback with a caret sufficiently solves inaccuracies.
The inaccuracies with MeasureString make it unusable for text processors. When selecting text, you need to be able to draw text in two parts (because the selected part has a different color) at exactly the same position (other text will start to 'jump around' if you select stuff). AFAIK this isn't possible with MeasureString+DrawString - it might work for some fonts (mostly the mono-spaced ones), but the inaccuracies will cause trouble for other fonts.
Use the Measure+Draw methods from the System.Windows.Forms.TextRenderer class instead - those work much better. You might have to specify some TextFormatFlags to keep the TextRenderer from adding padding.
|
|
|
|
|
Hi Daniel,
thanks for the info. I'll have to experiment with it some day, I've never used TextRenderer so far.
Cheers.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi,
I am using unmanaged Dll in a managed C# project, where callbacks are made from the unmanaged code to the managed code.
My project compiles fine, when I run the application (in debug mode), which is basically a client that communicates with a server application, intermittently I get a NullReferenceException dialog box. But my problem is it does not point to a specific line of code where this exception is occurring. The dialog just shows in the middle of the IDE (VS 2008) and I have to stop the application.
Does anyone know how can I verify where this exception is occurring???
Appreciate your suggestions.
|
|
|
|
|
This happens sometimes when error is happening to an external dll. Say you have added a dll called a.dll which doesnt have the pdb associated with it or no Debug Symbols for that dll is loaded into memory... Thus .NET cant show you the actual source, and hence shows this error.
You can see the assembly code.. but if you dont know it, it wouldnt be meaningful to you.
What you can do is always add the dll from bin folder of your project. This ensures that the dll is loaded with debug symbols.
|
|
|
|
|
I have added the dll from bin folder of the project.
modified on Sunday, September 20, 2009 4:43 PM
|
|
|
|
|
I mean I have been doing that already before I posted this question, It did not help.
|
|
|
|
|
try copying both the DLL and the PDB file to the EXE folder.
that may suffice to get line numbers in your exception.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Both of them are in the "bin\x64\Debug\" along with the EXE.
|
|
|
|
|
What exactly the operation you are doing when you encounter this exception..??
the line no is not shown only when the source is not associated with debug information..
Debug line by line to find exact line where error is occurring..
Also see if there is anything in InnerException (Though I think it should be null)
|
|
|
|
|
|
nicromonicon wrote: is there such a thing?
And this relates to C# how?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
actually i didnt know where to post it, its network related but i couldnt find network category
|
|
|
|
|
So why on earth did you pick C#? It looks like you just picked a random forum, which isn't going to get you an answer. You might as well have asked this in Pig Farmers Weekly. You could have chosen the General IT Issues or, more appropriately, the Hardware and Devices forum.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
i did it because i wanted to know - also - how to connect to a proxy via C#
anyway-Mr.O'Hanlon-dont you think by the time it took you to write down those not-so-funny rants and cheap jokes, you could've answered my question instead?
a true professional would have answered my question, or at least guide me to the correct forum
so next time, if you do know the answer,by all means, if you dont, please refrain from making useless comments..other members are not here for the jokes
|
|
|
|
|
nicromonicon wrote: i did it because i wanted to know - also - how to connect to a proxy via C#
Then you should have stated that, and not asked an unrelated question. We can't read your mind for you.
nicromonicon wrote: anyway-Mr.O'Hanlon-dont you think by the time it took you to write down those not-so-funny rants and cheap jokes, you could've answered my question instead?
No I don't. This isn't the right forum for this - think about it for a minute. People search these forums for answers to questions; why do you think that somebody would look for a network question in the C# forum? It makes no sense.
nicromonicon wrote: a true professional would have answered my question, or at least guide me to the correct forum
And had you read my reply you'd see that I suggested two possible forums for you.
Anyway, I'm not going to bother reading your replies now - whenever somebody replies in the way you just have, it's apparent they are incapable of a rational dialogue.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
nicromonicon wrote: other members are not here for the jokes
Oh yes we are 
|
|
|
|
|
In Crystal report viewer, is there any way to rename the tab [Main Report] showing at the top of the report to any name which I will decide?
|
|
|
|
|
i have the following field:
trxn_date
trxn_category
trxn_description
trxn_total_amount
trxn_discount_amount
trxn_net_amount
I want to display a monthly report (all above excep trxn_category) based of the selected month so it will list by days from 1 to last day of the month.
at the bottom, I want to display the list by category for the whole month (without trxn_date and trxn_description) so it will be:
trxn_category
trxn_description
trxn_total_amount
trxn_discount_amount
trxn_net_amount
can you please guide...
|
|
|
|
|
Let me know what reporting engine you are using... Is it Crystal Report, Microsoft Reporting (RDLC) or any other??
In any case just make grouping to those elements and place the group elements in the group footer. Use appropriate functions, and I think it will adjust automatically.
|
|
|
|
|
Hi guys,
I have this code in my form1_load event:
RegistryKey licenseCheck = Registry.LocalMachine.OpenSubKey(@"software/openorganise");
string licenseCo = licenseCheck.GetValue("tlb").ToString();
DateTime licenseDate = Convert.ToDateTime(licenseCo);
if (licenseDate.AddDays(30) == System.DateTime.Now)
{
MessageBox.Show("Your OpenOrganise License Has Expired. Please Purchase A New One.", "OpenOrganise Message.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
}
now, ive got a config value that sets it to write to a file if its the first time run or not, etc etc, this works fine, in the event of a first run i have:
RegistryKey licenseKey;
licenseKey = Registry.LocalMachine.CreateSubKey(@"Software\openorganise");
licenseKey.SetValue("tlb",DateTime.Now);
Registry.LocalMachine.Flush();
However, when running the application i get: "object referance not set to a instance of a object"
Im stumped to as why. I even went and manually made the reg key.
thanks,
Ben.
|
|
|
|
|
Hi,
some remarks:
1.
exceptions tend to contain a lot of information, however you need to look at all of it, i.e. use Exception.ToString() instead of Exception.Message
one of the pieces of information it offers is a filename and linenumber; that would point straight to the culprit line. Also teach your IDE to always show line numbers in edit windows, see here[^].
2.
Recent Windows versions don't allow a regular user to access/modify system settings that would extend to other users; the LocalMachine registry hive would be in that category.
3.
Your expiration test needs a less than comparison, not an equals. DateTimes seldom are equal as they contain information up to the tick (one tenth of a microsecond).
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|