|
hello guys
i have a problems with the following code but i can't identify any on having idea please help me
the problems are:
1 when activate and deactivate it doesn't paint NCArea
2 it flickers
3 it doesn't give the feel like windows default title
//NCButton class
using System;
namespace WindowsApplication1
{
///
/// Summary description for NCButton.
///
public class NCButton
{
System.Drawing.Image nBitmap,fBitmap,pBitmap;
System.Drawing.Rectangle buttonRectangle;
public NCButton()
{
//
// TODO: Add constructor logic here
//
nBitmap = null;
fBitmap = null;
pBitmap = null;
}
public System.Drawing.Image NormalButtonImage
{
get
{
return nBitmap;
}
set
{
nBitmap = value;
}
}
public System.Drawing.Image FocusedButtonImage
{
get
{
return fBitmap;
}
set
{
fBitmap = value;
}
}
public System.Drawing.Image PressedButtonImage
{
get
{
return pBitmap;
}
set
{
pBitmap = value;
}
}
public System.Drawing.Rectangle ButtonRectangle
{
get
{
return buttonRectangle;
}
set
{
buttonRectangle = value;
}
}
}
}
//form1 class
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
///
/// Summary description for Form1.
///
///
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
///
/// Required designer variable.
///
///
private ArrayList ncButtons;
[Category("Custom Mouse Events")]
private event System.Windows.Forms.MouseEventHandler NonClientMouseMove;
private event System.Windows.Forms.MouseEventHandler NonClientMouseDown;
private event System.Windows.Forms.MouseEventHandler NonClientMouseUp;
System.Drawing.Bitmap imgTitle,imgLRBorder,imgBBorder,imgButtons;
Rectangle bt1,bt2,bt3;
private System.Windows.Forms.ImageList imageList1;
private System.Drawing.Graphics graphics;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
ncButtons = new ArrayList();
NCButton bt = new NCButton();
bt.FocusedButtonImage = new Bitmap(@"C:\btimages\fmin.bmp");
bt.NormalButtonImage = new Bitmap(@"C:\btimages\nmin.bmp");
bt.PressedButtonImage = new Bitmap(@"C:\btimages\pmin.bmp");
Rectangle rect = new Rectangle(0,0,bt.NormalButtonImage.Width,bt.NormalButtonImage.Height);
bt.ButtonRectangle = rect;
ncButtons.Add(bt);
bt = new NCButton();
bt.FocusedButtonImage = new Bitmap(@"C:\btimages\fmax.bmp");
bt.NormalButtonImage = new Bitmap(@"C:\btimages\nmax.bmp");
bt.PressedButtonImage = new Bitmap(@"C:\btimages\pmax.bmp");
rect = new Rectangle(0,0,bt.NormalButtonImage.Width,bt.NormalButtonImage.Height);
bt.ButtonRectangle = rect;
ncButtons.Add(bt);
bt = new NCButton();
bt.FocusedButtonImage = new Bitmap(@"C:\btimages\fclose.bmp");
bt.NormalButtonImage = new Bitmap(@"C:\btimages\nclose.bmp");
bt.PressedButtonImage = new Bitmap(@"C:\btimages\pclose.bmp");
rect = new Rectangle(0,0,bt.NormalButtonImage.Width,bt.NormalButtonImage.Height);
bt.ButtonRectangle = rect;
ncButtons.Add(bt);
imgTitle = new Bitmap(@"C:\Skin Images\title.bmp");
imgLRBorder = new System.Drawing.Bitmap(@"C:\Skin Images\LRF.bmp");
imgBBorder = new System.Drawing.Bitmap(@"C:\Skin Images\BottomF.bmp");
imgButtons = new System.Drawing.Bitmap(@"C:\Skin Images\Button.bmp");
//graphics = new System.Drawing.Graphics();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
protected override void WndProc(ref Message m)
{
if(m.Msg == 0x1)//once when application starts
{
}
else if(m.Msg == 0x85 || m.Msg == 0x86)//nc_paint //nc_activate
{
IntPtr regn = m.WParam;
IntPtr hdc = Form1.GetDCEx(m.HWnd,regn,0x1 | 0x30);
if(hdc != IntPtr.Zero)
{
graphics = Graphics.FromHdc(hdc);
}
RepaintTheNCArea();
}
else if(m.Msg == 0xA0 )//nc mouse move
{
if( MouseMoveHandling(FindMousePosition()))
return;
}
else if(m.Msg == 0xA1 )//nc mouse button down
{
if( MouseDownHandling(FindMousePosition()) )
return;
}
else if(m.Msg == 0xA2 )//nc mouse button up
{
if (MouseUpHandling(FindMousePosition()))
return;
}
label1.Text = m.Msg.ToString();
base.WndProc (ref m);
}
[DllImport("User32.DLL", EntryPoint="GetDCEx", SetLastError=true,
CharSet=CharSet.Ansi, ExactSpelling=true,
CallingConvention=CallingConvention.Winapi)]
public static extern IntPtr GetDCEx(
IntPtr hWnd, // handle to window
IntPtr hrgnClip, // handle to clipping region
int flags // creation options
);
[DllImport("User32.DLL", EntryPoint="GetWindowDC", SetLastError=true,
CharSet=CharSet.Ansi, ExactSpelling=true,
CallingConvention=CallingConvention.Winapi)]
public static extern IntPtr GetWindowDC(
IntPtr hWnd // handle to window
);
private bool MouseMoveHandling(Point mousePosition)
{
Rectangle rect = ((NCButton)this.ncButtons[0]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[0]).FocusedButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[1]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[1]).FocusedButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[2]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[2]).FocusedButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
return true;
}
RepaintTheNCArea();
return false;
}
private bool MouseDownHandling(Point mousePosition)
{
Rectangle rect = ((NCButton)this.ncButtons[0]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[0]).PressedButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[1]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[1]).PressedButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[2]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[2]).PressedButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
return true;
}
RepaintTheNCArea();
return false;
}
private bool MouseUpHandling(Point mousePosition)
{
Rectangle rect = ((NCButton)this.ncButtons[0]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[0]).NormalButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[1]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[1]).NormalButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[2]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[2]).NormalButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
return true;
}
RepaintTheNCArea();
return false;
}
private Point FindMousePosition()
{
/*int l = (int)m.LParam;
int x = l & 0xffff;
int y = (int)((l & 0xffff0000) >> 16);
label1.Text = x.ToString();
label2.Text = y.ToString();*/
Point pt = System.Windows.Forms.Cursor.Position;
Point ptScreen = Cursor.Position;
Point ptClient = PointToClient(ptScreen);
ptClient.Y += 30;
//label1.Text = ptClient.X.ToString();
//label2.Text = ptClient.Y.ToString();
return ptClient;
}
private void RepaintTheNCArea()
{
if(graphics != null)
{
graphics.DrawImage(imgTitle,0,0,this.Width,30);
graphics.DrawImage( ((NCButton)ncButtons[0]).NormalButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
graphics.DrawImage( ((NCButton)ncButtons[1]).NormalButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
graphics.DrawImage( ((NCButton)ncButtons[2]).NormalButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
}
}
private void Form1_Resize(object sender, System.EventArgs e)
{
int totalButtonsWidth = 0;
int x = 0, y = 0 , w = 0, h = 0;
int space = 5;//space b/w the buttons;
for(int i = 0 ; i < ncButtons.Count ; i++)
{
totalButtonsWidth += ((NCButton)ncButtons[i]).NormalButtonImage.Width;
}
x = this.Width - ( (space * 2) + totalButtonsWidth) ;
y = 0;
w = ((NCButton)ncButtons[0]).NormalButtonImage.Width;
h = ((NCButton)ncButtons[0]).NormalButtonImage.Height;
Rectangle rect = new Rectangle(x,y,w,h);
((NCButton)ncButtons[0]).ButtonRectangle = rect;
x += (space + w) ;
y = 0;
w = ((NCButton)ncButtons[1]).NormalButtonImage.Width;
h = ((NCButton)ncButtons[1]).NormalButtonImage.Height;
rect = new Rectangle(x,y,w,h);
((NCButton)ncButtons[1]).ButtonRectangle = rect;
x += (space + w) ;
y = 0;
w = ((NCButton)ncButtons[2]).NormalButtonImage.Width;
h = ((NCButton)ncButtons[2]).NormalButtonImage.Height;
rect = new Rectangle(x,y,w,h);
((NCButton)ncButtons[2]).ButtonRectangle = rect;
}
}
}
|
|
|
|
|
hi,
Is it possible to explain your little more specific. What i mean is, what is your real requirement and where you fond problem. And what is your problem. When your form flickering. And what you mean by activate and deactivate. Is it forms activate and deactivate or something else
Sreejith Nair
|
|
|
|
|
hi
actually i am trying to create my own title bar(paint over the windows title) for this purpose i have images for my own buttons and for the title. on EM_NCPAINT i just paint these images over the title, i am also using the mouse events for the title buttons they also update my title bar.
But the problem is when i update my title bar as u seen in the previous message my window's titlebar flickers.
and the other problem is when i avtivate/deactivate my form (another app become over my form or vice versa it doesn't paint over the title bar.
by
|
|
|
|
|
hi,
So when ever you click on form say , for activating or deactivating you need to re- draw the client area. I mean the base form. Right. You can call Invalidate() of your base class to re-draw the region. And also you can try use DoubleBuffering to avoid flickering. I know this is not at all ultimate for you. But this is what i can suggest you now. Why i suggest you the double-buffering is, that you are trying to customize your title bar.
Sreejith Nair
|
|
|
|
|
hi
do u have any clue how to achieve DoubleBuffering in C# if yes please help me
thanx
|
|
|
|
|
hi,
In this point of time, I can't sound much in GDI+ .What i can do is , i can suggest one url page for you. There you will get more nice articles which will guide you to , how to use Double Buffering.
http://www.codeproject.com/script/Articles/list_articles.asp?userid=6556
please go to the Multimedia -> GDI + link. There you will get nice stuffs for DoubleBuffering with very nice exapmle.
Sreejith Nair
|
|
|
|
|
Hi Asif,
Add Paint Event handler and below line of code. This will solve your problem.
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
this.graphics = e.Graphics;
}
Do Revert back whether it could solve your problem or not.
Regards,
Jay.
|
|
|
|
|
this.graphics contains the handle of Non Client area if i equal it to my client area how will i paint over NC
thanx
|
|
|
|
|
Hi Asif,
Check out this code....
[DllImport("User32.Dll")]
public static extern IntPtr GetSystemMenu(int hWnd, bool bRevert);
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
IntPtr hTitle = GetSystemMenu(this.Handle, false);
this.graphics = Graphics.FromHwnd(hTitle);
}
Regards,
Jay.
|
|
|
|
|
GetSystemMenu only gets the graphics handle for the system menu .
i have the graphics handle for non client area but the problem is when i draw an image over another image it flickers is there any concept of double buffering
by
|
|
|
|
|
|
|
Hi,
I'm using a PropertyGrid on a form to display the properties of a Control. But my property grid only contains a property page - the events page is missing. So I tried to add the events page with
System.Windows.Forms.PropertyGrid.PropertyTabCollection coll = myPropertyGrid.PropertyTabs;
coll.AddTabType(typeof(System.Windows.Forms.Design.EventsTab));
When I use coll.Count() to receive the numbr of tab pages it is still 1 (the property page). I also tried the Microsoft Example and inherited my own event tab page class and used it for a UserControl with
[PropertyTabAttribute(typeof(TypeEventsTab),PropertyTabScope.Component)]
This works fine in Design time in Visual Studio but not at runtime for the property grid on my form. What's wrong?
Claudia
|
|
|
|
|
Claudia Peschke wrote:
This works fine in Design time in Visual Studio but not at runtime for the property grid on my form. What's wrong?
You will have to fool the enviroment that it is in design mode then. google for "designerhost"
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
Hi all,
How can i program outlook express in c#, e.g. get email items in
the inbox of outlook, activate outlook express to check emails ?
Thanks
Patrick
|
|
|
|
|
Hi simplest question how i can convert System.UInt32 to Integer and backward.
THANK
|
|
|
|
|
System.UInt32 u = 0;
int x = (int)u;
u = (UInt32)x;
Just be carefull that the values are valid or you will get an exception.
Incase you are going to try and catch it i think the exception is InvalidCastException but i'm not sure on that one.
Kev
|
|
|
|
|
exhaulted wrote:
Just be carefull that the values are valid or you will get an exception
You won't unless you ask for one. C# will just convert it without fuss even if the value is out of range for the new type.
exhaulted wrote:
the exception is InvalidCastException but i'm not sure on that one
It is a System.OverflowException
Do you want to know more?
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
So long as the values are in the range 0 to 2147483647 then there are no problems.
If you exceed the upper value the operation overflows. For instance: (int)UInt32.MaxValue results in -1 (negative one). This does NOT throw an exception.
If you need an exception to be thrown you can wrap the casting operation inside a checked statement.
Consider this code:
uint a = UInt32.MaxValue;
Console.WriteLine("a = {0}", a);
int b = (int)a;
Console.WriteLine("b = {0}", b);
int c = checked((int)a);
Console.WriteLine("c = {0}", c);
Does this help?
Do you want to know more?
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
I'm trying to insert by using adapter1.Update(dataset1);
but I get an exception
Devil Linux
|
|
|
|
|
What exception did you get????
Have you included a primary key in the table in your dataset?
The update method requries the primary key to be able to update.
Kev
|
|
|
|
|
Have just read your Subject again, are you trying to update your table using the update statement? If so then you should know that the update method of a dataAdapter is only used to update a database with changes made in your dataSet.
To insert rows into your table you need to use the dataAdapter.Fill() method.
Kev
|
|
|
|
|
I'm looking for some code which do the dial up through phone line?
would be nice if anyone can share thier code with me.
|
|
|
|
|
To see what I am talking about, create a WinForm application and add a RichTextBox to the form. Compile the application and run it.
Start typing into the richtextbox. Then paste an image into it. Then continue typing on the line below or above the pasted image. The flicker is unbearable.
If someone can give me some direction on overriding the OnPaint(PaintEventArgs pe) event to be able to successfully paint both images and text, it would be helpful and very much appreciated.
I posted once before and nobody provided any solution.
Thank you in advance for any help.
JB
|
|
|
|
|