I had posted my message on the windows forms newsgroup and got a reply to
ask you guys about the query.
TIA,
--Saurabh
Try posting in the microsoft.public.dotnet.framework.drawing newsgroup.
There are several people there who can help you with this. Specifically Bob
Powell.
Cheers,
Paul
"Saurabh" <sau...@nagpurcity.net> wrote in message
news:eBmySdn5...@TK2MSFTNGP10.phx.gbl...
> Hi All,
>
> I have added my own button in the titlebar of a form next to the close
> button. Everything works fine but when I resize the dialog, the button
does
> not get redrawn at a correct location.
>
> I calculate the button position relative to the close button and draw a
> button using ControlPaint, but if i increase the size of the form briskly,
> the distance between the close button and my button increases till the
next
> redraw. If i reduce the width of the form by dragging the border inwards,
my
> button gets drawn overlapping on the close button. I want my button to be
at
> a fixed position relative to the close button. Is there any way to achieve
> this?
>
> TIA,
>
> --Saurabh
>
>
If the button moves I suppose that the result of that is flawed somehow.
Post some code.
--
Bob Powell [MVP]
C#, System.Drawing
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
Read my Blog at http://bobpowelldotnet.blogspot.com
"Saurabh" <sau...@nagpurcity.net> wrote in message
news:%238g2xTo...@TK2MSFTNGP11.phx.gbl...
Size CloseButtonSize = SystemInformation.CaptionButtonSize;
int X = Bounds.Width - 4 - CloseButtonSize.Width * 2;
int Y = 6;
MyButton.Bounds = new Rectangle(X, Y, 15, 15);
---------end of code----------
Please ignore the constant values as they came there by actually seeing the
adjustment on screen. Anyways, since I calculate the position for my button
relative to the close button, I expect it to remain at a same distance to
the close button. I'll recreate it in a simple project and post it soon.
Thanks
--Saurabh
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eApcF$o5DH...@TK2MSFTNGP10.phx.gbl...
I saw this code on the other group. Please post something a bit more
comprehensive like the whole WM_NCPAINT handler.
--
Bob Powell [MVP]
C#, System.Drawing
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
Read my Blog at http://bobpowelldotnet.blogspot.com
"Saurabh" <sau...@nagpurcity.net> wrote in message
news:e3bcNCy5...@TK2MSFTNGP10.phx.gbl...
--Saurabh
-----------code-----------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace ShortButComplete
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
[DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
//Message constants
public const int WM_NCPAINT = 0x0085;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCPAINT:
{
base.WndProc (ref m);
IntPtr hDC = GetWindowDC(m.HWnd);
Graphics g = Graphics.FromHdc(hDC);
PaintNC(m.HWnd);
g.Dispose();
ReleaseDC(m.HWnd, hDC);
m.Result = IntPtr.Zero;
}
break;
default :
base.WndProc(ref m);
break;
}
}
protected void PaintNC(System.IntPtr hWnd)
{
IntPtr hDC = GetWindowDC(hWnd);
Graphics g = Graphics.FromHdc(hDC);
int CaptionHeight = Bounds.Height - ClientRectangle.Height; //Titlebar
Size CloseButtonSize = SystemInformation.CaptionButtonSize;
int X = Bounds.Width - 4 - CloseButtonSize.Width * 2;
int Y = 6;
ControlPaint.DrawButton(g, X, Y, 15, 15, ButtonState.Normal);
g.Dispose();
ReleaseDC(hWnd, hDC);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(322, 295);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
--------end of code-------------
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:uzAV3Jy5...@TK2MSFTNGP11.phx.gbl...
--
Bob Powell [MVP]
C#, System.Drawing
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
Read my Blog at http://bobpowelldotnet.blogspot.com
"Saurabh" <sau...@nagpurcity.net> wrote in message
news:%23y%23qVSy5...@TK2MSFTNGP09.phx.gbl...
What I am saying is, If I briskly drag the right hand resize border
outwards, the distance between the close button and my button increses TILL
WM_NCPAINT is sent again because of some reason. Its not a lag. If I drag
the border and leave it as it is, I can actually see them far apart
similarly is i reduce the size i can see them overlap.
--Saurabh
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%23Rj8B9y...@TK2MSFTNGP09.phx.gbl...
Are you saying that when you drag the window of button drifts off-station
and remains there after you've released the mouse?
--
Bob Powell [MVP]
C#, System.Drawing
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
Read my Blog at http://bobpowelldotnet.blogspot.com
"Saurabh" <sau...@nagpurcity.net> wrote in message
news:uKoSPL15...@TK2MSFTNGP09.phx.gbl...
When you recieve WM_NCPAINT, post (PostMessage) a WM_USER to your window.
Then add a case WM_USER: to your switch, and when you recieve the message,
draw the button:
> > > case WM_USER:
> > > {
> > > base.WndProc (ref m);
> > > IntPtr hDC = GetWindowDC(m.HWnd);
> > > Graphics g = Graphics.FromHdc(hDC);
> > > PaintNC(m.HWnd);
> > > g.Dispose();
> > > ReleaseDC(m.HWnd, hDC);
> > > m.Result = IntPtr.Zero;
> > > }
> > > break;
I'd try it myself but I'm busy...
"Saurabh" <sau...@nagpurcity.net> wrote in message
news:uKoSPL15...@TK2MSFTNGP09.phx.gbl...
Actually I was away for the week, I did not try anything during that time.
Thans a lot for your inputs!!
--Saurabh
"Saurabh" <sau...@nagpurcity.net> wrote in message
news:uKoSPL15...@TK2MSFTNGP09.phx.gbl...
--Saurabh
"Saurabh" <sau...@nagpurcity.net> wrote in message
news:%23tKKu4y...@TK2MSFTNGP12.phx.gbl...
I have to make the same task too (add additional button to title bar)
I read yours interesting discussion, I've got a lot of useful info.
Do you solve all the problems? Do you have any additional tips or info?
Thanks in advance.
Thanks,
--Saurabh
"Yevgeny" <1q...@mail.ru> wrote in message
news:8452a379.04022...@posting.google.com...
I've just started an article on non-client operations for Well Formed. I'll
send you some code when I get done.
--
Bob Powell [MVP]
C#, System.Drawing
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
Read my Blog at http://bobpowelldotnet.blogspot.com
"Saurabh" <sau...@nagpurcity.net> wrote in message
news:eYn1qG5%23DHA...@TK2MSFTNGP11.phx.gbl...
--Saurabh
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%23IToh15%23DHA...@TK2MSFTNGP09.phx.gbl...
I just want to say that I found excellent tutorial on:
http://www.catch22.org.uk/tuts/titlebar.asp. This tutorial was also
mentioned in another discussion.
This code wrote on the C and it took me few days to "translate" it to
C#, but it works and that's all what I need. :-)
Yevgeny
"Saurabh" <sau...@nagpurcity.net> wrote in message news:<eeVicm6#DHA....@TK2MSFTNGP10.phx.gbl>...
I just want to say that I found excellent tutorial on:
http://www.catch22.org.uk/tuts/titlebar.asp. This tutorial was also
mentioned in another discussion.
This code wrote on the C and it took me few days to "translate" it to
C#, but it works and that's all what I need. :-)
Yevgeny
"Saurabh" <sau...@nagpurcity.net> wrote in message news:<eeVicm6#DHA....@TK2MSFTNGP10.phx.gbl>...