|
In most cases you let WndProc handle the WM_NCPAINT method, then overpaint it yourself. A few of the controls will let you paint the border without having it painted by WndProc first, but many won't. I know this is double-painting, but with some controls there's just no way around it, save for rebuilding the entire control yourself. Also, after painting the border on some controls you will need to Send WM_ERASEBKGND and WM_PAINT after you've painted the border so that things like scrollbars are re-drawn.
Also, take care with the way you are creating your graphics object for painting. Some controls will work with a simple Graphics.FromHdc(Handle), but others will need to get their graphics instance from user32.dll like this:
[DllImport("user32.dll")]<br />
private static extern IntPtr GetWindowDC(IntPtr hWnd);<br />
Graphics g = Graphics.FromHdc(GetWindowDC(Handle));
One last note, make sure you don't set UserPaint, DoubleBuffer, AllPaintingInWmPaint for controls that you are going to paint borders on using the WM_NCPAINT WndProc override - doing so will only create you much frustration.
There are many controls in the base library that need to be WndProc painted, and all of them have their own little quirks. It took me a couple of days to learn the ins and outs of each, but once you've got the basic ideas it's fairly straight forward.
|
|
|
|
|
This was one of the first things I tried, I set the border to FixedSingle, so that it was 1 pixel around the edge, and then I painted over the border after the control had finished painting it. Of course, this causes flicker when resizing, which was what I was keen to avoid.
Drawing a damn rectangle isn't always as easy as it first seems
|
|
|
|
|
Are you interested in just the treeview, or all the controls previously listed?
|
|
|
|
|
Here's how to user-paint the border of the TreeView control:
1) Create a class that inherits from System.Windows.Forms.TreeView
2) Add the follwing using directive:
using System.Runtime.InteropServices;
3) In the class body, add the following user32.dll wrapper method:
[DllImport("user32.dll", CharSet=CharSet.Auto)]<br />
private static extern IntPtr GetWindowDC(IntPtr hWnd);
4) Add the follwing WndProc override method:
protected override void WndProc(ref System.Windows.Forms.Message m)<br />
{<br />
if( m.Msg == 0x0085 )<br />
PaintBorder();<br />
else<br />
base.WndProc(ref m);<br />
}
5) Add the PaintBorder method:
<br />
private void PaintBorder()<br />
{<br />
Graphics g = Graphics.FromHdc(GetWindowDC(this.Handle));<br />
Rectangle r = new Rectangle(0, 0, Width, Height);<br />
<br />
<br />
g.Dispose();<br />
}<br /> That's it! Note that every control has it's own unique methods for border painting. This particular method will work only for some of the controls,
others will require the WM_NCPAINT to be handled by WndProc before you go painting border, causing a double-paint. Other controls require you to
create the Graphics object from the actual parent form rather than the control itself.
On final note, ensure the border style is 3D, not Single or none.
Hope this helps!
|
|
|
|
|
hi!
I want to make a snapshot mh, for example if you know the programm "Hypersnap". I have an window (lets say an IE window) and now I want to have a bitmap/jpg of a foto in that window...
hope its clear what i mean...
any ideas? (im have absolute none
thx
|
|
|
|
|
Here[^]
Use the code to capture the screen, then use their crop function to crop it to you control's this.ClientRectangle
I walk these roads,
I climb these mountains,
Though they are nothing,
But paths and hills,
for the only mountain is success,
and the only road is life.
|
|
|
|
|
Dear All,
Please let me know whether you know how to have reinstall feature in a Windows Installer .msi module. Normally when you setup an application and then run the .msi again, you have the repair and remove features, Now what I must do to have some other options like reinstall or upgrade to new versions?
Regards,
Sassan Komeili Zadeh
|
|
|
|
|
How about a bootstrap setup.exe that removes the current installation and then loads the new .msi file to install it. Other than that I'd think you'd have to use Installshield or Wise Installer to upgrade, or write your own app that checks current files to upgrade them if needed.
I walk these roads,
I climb these mountains,
Though they are nothing,
But paths and hills,
for the only mountain is success,
and the only road is life.
|
|
|
|
|
Dear Jonny,
Thanks.
Actually I used this solution before, but it is hard to manage upgrade mode with bootstrap and installer both.
regards,
Sassan
|
|
|
|
|
Sassan Komeili Zadeh wrote:
reinstall or upgrade
What's the difference between reinstall and repair?
For doing an upgrade, simply add a record into the new MSI's Upgrade table, telling it to upgrade the current project up to but not including the new version.
ie.
If you want to upgrade to v2.00.9 and the Upgrade Code of the project is {99999999-9999-9999-9999-999999999999} then you need the following in the Upgrade table:
Upgrade Code: {99999999-9999-9999-9999-999999999999}
Version Min: NULL
Version Max: 2.00.9
Language: NULL
Attributes: 1
Remove: NULL
ActionProperty: MYUPGRADEPROPERTY (call it whatever you like, as long as it's block-caps and not used elsewhere)
It's then advisable to add a property SecureCustomProperties, containing MYUPGRADEPROPERTY, so that this property can't be used by anything else. If there's already a SecureCustomProperties then you should add ";MYCUSTOMPROPERTY".
This should force a new version to remove an old version before installing.
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
Dear Paul,
Sorry for late reply.
Actually I have an application which has an storage folder and also a database which extracts user information. I want to repair module fix the functionality of application if for example some .dll files are missed but the storage and db are remained with the user previous data.
But in reinstall I want to erase DB and user storage in order to have everything as the first time user installs.
Can you help me with this scenario?
Thanks for the upgrade solution.
Regards,
Sassan
|
|
|
|
|
Sassan Komeili Zadeh wrote:
But in reinstall I want to erase DB and user storage in order to have everything as the first time user installs.
Can you help me with this scenario?
I would suggest this is a software job, not an installer job; but then I write installers for a living at the moment and I tend to suggest everything is a software job, rather than the installer.
It's not easy to add an entry path to the installer, unless you have InstallShield Developer or something else with a built in Dialog Editor.
You could add a custom action to the Repair which throws up a message box asking if the user wants to remove the database.
But I really would encourage you to make database creation and rebuilding part of the software itself. It's much easier and MUCH more controllable.
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
I have an obejct with some properties , one of those propps is a delegate..
now i would like to be able to show this in a propp grid , and let the user choose a method for the delegate prop (kinda like choosing events in c#)
any ideas?
//Roger
|
|
|
|
|
Roger J wrote:
I have an obejct with some properties , one of those propps is a delegate..
now i would like to be able to show this in a propp grid , and let the user choose a method for the delegate prop (kinda like choosing events in c#)
F#$$king cool idea I'm gonna use it
Roger J wrote:
any ideas?
TypeConvertor with Reflection, send me the code and I'll try figure it out.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Oh , forgot to say , in my case , it should not be so cool as you might think ,
it should be used in a control , so i want to be able to choose methods at designtime , and i guess the code doesnt need to be compiled ´for them to show up....
so i would guess reflection would not be the way to go (in my case) (??)
//Roger
|
|
|
|
|
Roger J wrote:
it should be used in a control , so i want to be able to choose methods at designtime , and i guess the code doesnt need to be compiled ´for them to show up....
I just got thinking...an event is a delegate, so why not just define the delegate as an event? Then you get all of the goodie for ZERO effort... I will look into it a bit more though.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
It could be a bit harder than I thought...
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hi All,
I need to iterate through a range of IP Address. What I have are a start and end IPAddress objects. How can I get the at the address in between these, we'll say add them to an ArrayList?
I have tried incrementing the long integer IPAddress.Address but this doesn't work as the address 10.20.30.40 is not 1 less than 10.20.30.41!!
Any ideas?
Thanks,
dp
|
|
|
|
|
IPAddress ip = IPAddress.Parse("192.168.0.1");
IPAddress ip2 = new IPAddress(
IPAddress.NetworkToHostOrder(
IPAddress.HostToNetworkOrder((int) ip.Address) + 1)
);
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hi,
I want to put an image to a simple button. I put an image to my button but page refreshes itself when I click. The button was created to open a popup window but it refreshes itself(main window) and this bothers me.
I need some opinions to solve this problem,I'm sure someone did a lot of buttons like this.The code will be running on the net, so that shorter codes will be better
Kind Regards,
-
kromozom@msn.com for MSN Messenger
-
|
|
|
|
|
JavaScript or set the target. I can never remember which one, either _self or _blank.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hi guys,
I was just wondering if this is only with me, or maybe somebody else out there experienced the same thing. When I put a button on my web form and connect a code to the click event of it (I use C#, but it shouldn't be language specific), then in the InitializeComponent() I got the code, something like:
this.btnSomething.Click += new System.EventHandler(this.btnSomething_Click);
and that is fine. Now after a while and after adding some more events and controls and deleteing some controls, it happens sometimes that the some lines gets deleted, and there will be no response to a click event!? The button is there, but it does not respond for it can not find its procedure. I suppose as I add controls on the form, this portion of code gets rewritten, but it is not supposed to lose any lines.
This is something similiar to binding controls to member variables in C++ 6 when programming database applications, when sometimes the wizard rewrites the code of DDX routines and tumbles up the order of member variables to controls.
If anybody of you have experienced the same, I would like to hear you experiences.
Thank you.
.
|
|
|
|
|
There is a bug in VS.NET where if you cut and paste controls the chosen event handlers get lost. I'm not positive, but it might happen if you copy/paste as well.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
The best way in VS .NET to add events to WinForm components is to either double click on the object in design view or on the property pane click events (the little lighning bolt) and pick what kind of event you want. Then VS will automaticly generate the code for that event. So you only have to code the functionality for the event. Any code added to the generated methods will be deleted or changed automaticly. So the best way is to make your own method or use VS to add it. Hope this helps.
JProd
|
|
|
|
|
Hello again.
Now I tried the Save and Load routines from the DUMeter project !
They're very good .. and I only gave my FileName and my TreeView-Control as
Object and the saving of the file works fine.
And it looks like the samples in the help.....
But now as I want to load that file again to fill my TreeView
I have a nice Exception :
An unhandled exception of type 'System.Xml.XmlException' occurred in system.xml.dll
Additional information: System error.
I have no idea what causes the error. The file isn't in use and was not edited.
He stops at the command where he starts reading the file :
System.Xml.XmlTextReader reader = new XmlTextReader(filename);<br />
<br />
while (reader.Read()) <-- HERE<br />
{ ....
Could someone please again help me in this case ?
|
|
|
|