|
Hi,
I've an applicaton where some Messages WndProc in main form are handled customly. There is custom non-client painting, hittest, mouse capturing and stuff... For some reason the default context menu, which should be displayd when rightclicked on non-client are is no showing (Move, Size, Minimize, Maximize, Close items) . Can you help me how to invoke the menu ?
Thanx
|
|
|
|
|
When you repaint the non-client area of the form you need to manually code how the titlebar handles events. You will have to capture the mouse when it clicks a specifc area and then use the API command SendMessage to send API window message constants to emulate events of a normal window.Add Transparent Menus and XP Titlebar Buttons to your application[^] is an article that I wrote that shows how to do this with a custom drawn help button on the title window.
Hopefully this helps.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Hi
Is it possible to dynamically load a Type from an assembly and knowing what type the base class is call static methods from it?
If so, how?
Cheers
|
|
|
|
|
Yes you need to know some info though:
(FullyQualifiedTypeName)Assembly.Load(AssembleName).CreateInstance(className)
If you mess up by not including the full namespace the above call will not work.
Hope that helps.
Ben
|
|
|
|
|
Well i have a textbox (actually, i have about 14) that check the input to make sure the user doesn't put any invalid characters in.
So far, the checking is done in the TextChanged event, and it checks the last character that the user typed in. But if the user pasted in some text, it would only check the last character that was put in.
So, how can i tell if something has been pasted into my textbox, rather than typed?
|
|
|
|
|
Sometimes you might want to prevent pasting into your textbox. You can do this by check keypress event and looking for Ctrl-V or Shift-Ins. Even this isn't completely foolproof, but it will cover it pretty well.
Hope that helps.
Ben
|
|
|
|
|
Thats just not practical though. I for one wouldn't want to type in 20 lines of seemingly random letters and numbers. Because thats what people will be putting in. I'll keep thinking on it.
|
|
|
|
|
I guess the next thought then is to use the key press event to check for ctrl-v or Shift-Ins and then do some extra checking on the text box after that. Checking the key press event is the only way I can think of the app knowing someone just pasted something in the text box.
Ben
|
|
|
|
|
Why don't you handle the Validating event?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hmm, apart from checking the whole textbox everytime the user changes anything, i could get the text from the clipboard, and compare it to the textbox, if i find it matches, then they just pasted it in and i check the string for invalid characters.
It'd be a little more complicated that that of course.
I could also override the paste message, and do something there. But that would require even more messing around.
|
|
|
|
|
Have you looked at using a "MaskedTextBox"?
Phil
|
|
|
|
|
No, but i sorted it now. Perhaps next time.
|
|
|
|
|
Any reason you can't just validate the TextBox when the LostFocus event fires?
This allows the user to catch their own mistakes and fix them without causing the validation code to run needlessly. They haven't really "finished" until they shift focus elsewhere, so let them freely edit the text and simply validate it when they are "done".
|
|
|
|
|
I recently deployed an application I built on a client's server. When I wrote and tested this app on my machine (Celeron 2.8GHz 1GB ram), it took most of the processor power and tons of ram. Now that it is on the production server(4 processor 2.0 GHz 2GB ram), it takes less total ram then on my machine and only about 4% processor power. With all that being said it doesn't run any faster than it did on my machine... Any ideas on why the app just take up more resources and run faster? I did check the task manager and saw that none of the 4 processors were taking more than 10% or so on the server.
I know that I didn't give any info on the app itself, but I'm more curious about the theory at this point.
Thanks!
Hogan
|
|
|
|
|
Often performance issues have more to do with Database stuff then with the app itself. I would guess this might be the common thread between running it locally and on the production server. If some indexes need to be created on tables etc on the database to speed the app up it would affect both the prod server and your local box.
Hope that helps.
Ben
|
|
|
|
|
Ben,
Thanks for your idea, but I don't think that is it. In both instances, I am running the Microsoft SQL Server on the same box the app is running on. Any other ideas?
Hogan
|
|
|
|
|
I guess I would need a little more info. I am guessing this is a windows app? windows service? When you ran it on your box where you running via Visual studio? Or were you just running it via launching the exe. If you were running via VS that would take more memory. I am guessing that is not the case.
As far as why it uses less memory on your prod server, it might be because you are running sql server on the prod server. Sql server will more or less say this memory is mine you can't touch it. So you app might have used up more memory if it was allowed to.
So the fact that your app uses so much memory leads me to think that it is probably using virtual memory for what ever process you are running. So that means it is using hard disk space to page its ram memory. If you are using so much memory you start paging to disk like that, it can slow down a process.
Perhaps you are serializing large objects. I have found it is better to write the large objects to disk and clean up the files later, instead of just using RAM memory.
If you are using serialization stuff in sql server that is also slow especially the larger the serialize objects get.
Really it is hard to guess past that with out knowing more details of what you app is doing.
So there are a couple of stabs in the dark. Hope it helps.
Ben
|
|
|
|
|
Hi,
from the little you told us, I've got a feeling your app contains a busy loop
(i.e. a loop checking for something without including a delay such as Thread.Sleep)
and this loop runs many many cycles on a single-threaded CPU, whereas it gets statisfied
rather soon on a hyperthreading/multi-processor system. On the single-threaded CPU
Windows would assign most CPU cycles to the thread with the busy loop, and only few
are devoted to the next one or two ready threads; having more threading hardware would
give this/those other threads more opportunity to run, hence significantly reduce
the number of busy loop iterations.
If this is right, you should
1. look for the busy loop (might be as simple as while(someBool) {} )
2. and at least insert a delay in there, say Thread.Sleep(50)
which turns it into a polling loop (it no longer is a busy loop since it sleeps most of the time)
3. or better yet find a way to completely avoid the loop. The most appropriate way
would be to get the required synchronisation based on an event.
Hope this helps.
|
|
|
|
|
I have a database powered Windows application that uses Crystal Reports. Instead of loading a report that displays, say a list of all books that have been checked out, I would like the user to select the book title and then display the customized report. I have been reading a lot on discrete parameters, but I am unable to figure it out for some reason.
<br />
protected void SetParameterFields ()<br />
{<br />
ParameterFields paramFields = this.crystalReportViewer1.ParameterFieldInfo;<br />
ParameterField paramField = new ParameterField();<br />
paramField.Name = "book_name";<br />
ParameterValues curValues = paramField.CurrentValues;<br />
ParameterDiscreteValue discreteValue = new ParameterDiscreteValue();<br />
discreteValue.Value = "Huck Finn";<br />
curValues.Add(discreteValue);<br />
this.crystalReportViewer1.ParameterFieldInfo = paramFields;<br />
}<br />
<br />
Here "book_name" is a column in my database table.
When I display the report all records are displayed, not ones pertaining to Huck Finn.
What am I doing wrong and how do I correct it so I can get it to do what I need it to?
Thanks!
|
|
|
|
|
I can send a variable from Program.cs to Form1.cs by
Application.Run(new Form1(mode,fname));
How do I send a variable from Form1.cs to Program.cs
|
|
|
|
|
public string varForm1="Form1";
on form2 use value of variable varForm1
string varForm2 = varForm1;
I Love SQL
|
|
|
|
|
The method used depends on the intended use of the variable. If a certain action is to take place each time the variable changes, events are the way to go. However, if the variable is one that only needs to be checked once in a while, then you could use a read only property.
Phil
|
|
|
|
|
I have three buttons which set an integer called retInt in form1. In progam.cs I want to exit the program with return retInt;
Under vis2003 this was not a problem as I just declared static int retInt and it was seen in Main() and form1. Now that Main() is in program.cs and the buttons are in form1() I cannot pass the value of retInt from form1 to program.cs.
Forgive my stupidity but in C++ I would just declare a global variable and be done.
|
|
|
|
|
Sounds like the read only property is the way to go. Look up "Properties" in your help to see how they can be done. If you don't like properties, you could use a public static variable.
Phil
|
|
|
|
|
how i do code when i need a list of layers for each shape in order not to inference the other
|
|
|
|