|
leppie wrote:
Can I use any class from the assesmbly?
Yep
leppie wrote:
I just want to use the static functions in a Win32 dll, how? Do I load to memory? Im totally clueless.
That is where it gets tricky.
I think the easiest method would be to write it to a file (with the same name it had when you compiled), and hope that the DLL doesn't get loaded until the imported method executes [so the DLL will be written to file before then]. I think there is a slight problem. From what I have heard, the dll is in use until the program exits; so you never get a chance to delete the file.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thx James I will have a look
James T. Johnson wrote:
From what I have heard, the dll is in use until the program exits; so you never get a chance to delete the file.
Thanx for that bit of info.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I’ve been trying to figure out where to place some drawing code in my application. Sometimes, I want to paint OVER some controls slightly. If I place the custom painting code in the form’s Paint Event (even override OnPaint ) when the controls on the form are painted my custom paint job is overpainted by the controls. Is there someplace that I can do my painting AFTER the controls have been painted?
|
|
|
|
|
Im not so sure , but from what i understand is you need to draw to the Graphics object found at IntPtr.Zero. Look for more info, a couple days back.
IntPtr.Zero? u may ask. I read that that is allways the pointer to the current foreground window. So it all makes sense
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Hi leppie,
Actually passing IntPtr.Zero (i.e. null) to GetDC will return a handle to the screen. This is a fine solution (as suggested in a thread below by Li-kai Liu and AK) and this is what I am doing.
However, when I do this in the Form Paint event the Screen is painted fine, then the controls get painted and it erases what is drawn. So I’m left with my original Question:
Is there someplace that I can do my painting AFTER the controls have been painted?
Try this code out to see for yourself. Start a new project, place a button on the form. Then add the Form1_Paint event and place this code in that event:
Rectangle r = new Rectangle();
r = this.RectangleToScreen(button1.Bounds);
IntPtr hdc = GetDC(IntPtr.Zero); // get hdc for the screen
Graphics g = Graphics.FromHdc(hdc);
System.Drawing.Rectangle r1 = new Rectangle( r.X - 7,r.Y - 7,r.Width+14 ,r.Height+14);
System.Drawing.Region region = new Region(r1);
System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush((System.Drawing.Drawing2D.HatchStyle) 9,Color.Gray ,this.BackColor );
//This should COVER the button but the control is redrawn over it
g.FillRegion(hatchBrush, region);
/////////////////////////////////////
//Place this code outside the paint event:
/////////////////////////////////////
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
|
|
|
|
|
You might want to try something like this:
void MyPaintMethod()
{
Rectangle r = new Rectangle();
r = this.RectangleToScreen(button1.Bounds);
Graphics g = new Graphics.FromHwnd(this.Handle);
System.Drawing.Rectangle r1 = new Rectangle( r.X - 7,r.Y -7,r.Width+14 ,r.Height+14);
System.Drawing.Region region = new Region(r1);
System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush((System.Drawing.Drawing2D.HatchStyle) 9,Color.Gray ,this.BackColor );
g.Dispose();
}
I can't test this to see if it will work, but I am thinking this should be correct, thus you wouldn't need the DllImport portion.
HTH
Nick Parker
|
|
|
|
|
I didnt test it but it seems that all it would do is get the Graphics object to the form (i.e. your "this" = Form1). Then after this code is painted on the form the controls would be painted over it. Leaving me with the same problem.
I need to find a way to paint over the controls on the form. I simply dont know where to hook my code in.
|
|
|
|
|
|
Thanks Nick,
I took a look at these articles but they don't apply. I'm not trying to create a control. I need to draw over ANY control that is placed on my form.
|
|
|
|
|
It sounds like you need to have an otherwise invisible window on top of which to paint. This window can sit above all other controls, and it's painting won't be affected by the controls under it. This would only work under Win2k and above, though.
An uglier solution might be to attach event handlers to ALL of your child control's Paint events, so that you can repaint the screen whenever one of your child controls repaints itself. This will, however, lead to some unavoidable flicker...
--
Russell Morris
"Have you gone mad Frink? Put down that science pole!"
|
|
|
|
|
Hi all,
I have question about distributed application. I bought a book from Wrox, Professional C#.
And now, I am trying to work on one of the samples in chapter Distributed Application.
However, I got this error when I execute my client application:
"Trying to create a proxy to an unbound type."
Main purpose of the program is to create 2 small applications which execute a remote object
called Hello. It's using TCP as the channel. In both applications, I already put a reference to
remote object's namespace (DistributedApp1CL).
Server application has no problem at all, but client does. The error comes in this line:
Hello obj = (Hello)Activator.GetObject(typeof(Hello), "tcp://localhost:8086/Hi");
Does anyone know what this error means?
|
|
|
|
|
maybe because "tcp://localhost:8086/Hi" is a reference to a folder, and not the file that it is supposed to create something with?
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
That is how remoting is done; the server binds to an IP:port and a name
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
I added this to a form:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
}
On purpose i did not put base.OnPaint(e); in the method.
But the form gets painted and works as usual. Why?
|
|
|
|
|
Just a guess, but since you aparently did not put any other code in there could the compiler be optomising it out and never even including it the exe?
|
|
|
|
|
|
Hi Nish,
Perhaps, I’m making an incorrect assumption. Will overriding the OnPaint method prevent the controls placed on the form from appearing if I don’t call base.OnPaint ?
|
|
|
|
|
albean wrote:
Perhaps, I’m making an incorrect assumption. Will overriding the OnPaint method prevent the controls placed on the form from appearing if I don’t call base.OnPaint ?
This might seem strange to you, but even if you don't call the base class OnPaint, the form will draw itself neat and proper. Calling the base class only ensures that all the other delegates attached to this event are called.
Overriding OnPaint is not at all the same as handling CWnd::OnPaint in MFC or WM_PAINT in pure win32. If you really want to do all the painting on your own, override WndProc and handle WM_PAINT messages.
Regards,
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
albean wrote:
But the form gets painted and works as usual. Why?
The OnPaint handler is used to paint the surface of the form after Windows has done its painting but before controls have done theirs.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Hi,
I'm using SQL Server Desktop Engine. I need to add a new record, which has an autonumber field, and get that value. Any way to do it in one step??
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
In 1 Step? I can only do it in 2 steps:
I'm guessing that you are using an identity column.
If this is true then @@IDENTITY will give you the last identity inserted.
(Well, it gets some what complicated if there are triggers that are inserting rows into other tables that have identity columns so you need to watch out for that.)
I don't know much about the DataAdapter but you might want to run it and see what SQL it generates. I think it creates some stored procs that will return newly inserted records.
|
|
|
|
|
albean wrote:
I'm guessing that you are using an identity column.
Yes, that's how SQL converts Access's autonumber fields.
albean wrote:
If this is true then @@IDENTITY will give you the last identity inserted.
How do I use that?? I just barely know how to SELECT, INSERT, DELETE and UPDATE.
Thanks,
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
SELECT @@IDENTITY
If you created a stored procedure you could do this all in one fell swoop, however I would wait until you get more knowledge about SELECT, INSERT, UPDATE, and DELETE before looking into those.
If you have the budget I would highly recommend Wrox's SQL Server 2000 Programming for learning the in's and out's of, well, SQL Server 2000 programming [MSDE is SQL Server 2000 minus the GUI tools and some server optimizations]
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
|
I do what I can
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|