473,586 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changes Form Wide

2 questions

1. How do i set the whole form's opacity prop? Right now i have to set
an event handler for each element on the form. Is there are better way
to do this?

2. how do i make a form that has no border fully dragable... ie you can
click and hold any where to move it around the desktop

Thanks for any help inadvance

Jun 11 '06 #1
2 1219
> 2 questions

1. How do i set the whole form's opacity prop? Right now i have to set
an event handler for each element on the form. Is there are better way
to do this?
I'm not sure I understand what you're wanting to do....you should be able to
set the Opacity property on the form, and it will effect everything.
2. how do i make a form that has no border fully dragable... ie you can
click and hold any where to move it around the desktop


Okay, here goes (see code sample below):

1. Set up two private class variables, formPosition (Point), and mouseDown
(bool)
2. Set up three event handlers for MouseDown, MouseMove, and MouseUp. See
the code below for thier contents.
3. Add the handlers above to the form, as well as any other control you want
the user to be able to click on (so labels, panels, etc).

public class Form1 : Form
{

private Point _formLocation;
private bool _mouseDown;

public Form1()
{
InitializeCompo nent();
}

private void OnMouseDown(obj ect sender, MouseEventArgs e)
{
this.formLocati on = new Point(e.X,e.Y);
this.Cursor - Cursors.SizeAll ;
this._mouseDown = true;
}

private void OnMouseMove(obj ect sender, MouseEventArgs e)
{
if(this._mouseD own)
{
this.Location = new Point(this.Left - (this._formLoca tion.Left -
e.X), this.Top - (this._formLoca tion.Y - e.Y));
}
}

private void OnMouseUp(objec t sender, MouseEventArgs e)
{
this._mouseDown = false;
this.Cursor = Cursors.Default ;
}
}

Enjoy!
Jun 12 '06 #2
Casey Kramer wrote:

Okay, here goes (see code sample below):


<Code snipped>

Or you can override the WndProc method of the form. This should only
be used with captionless forms as it will interpret the clicking of the
close button [x] in the corner as moving the form. What it does is
trick Windows into thinking you have the mouse cursor

//C# code
protected override void WndProc(ref Message m)
{
const int WmNcHitTest = 0x84;
const int HtCaption = 2;

if (m.Msg == WmNcHitTest)
m.Result = new IntPtr(HtCaptio n);
else
base.WndProc(re f m);
}
'VB Code
Protected Overrides Sub WndProc(ByRef m As
System.Windows. Forms.Message)
Const WmNcHitTest As Integer = &H84
Const HtCaption As Integer = &H2

Debug.WriteLine (m.ToString)

If m.Msg = WmNcHitTest Then
m.Result = New IntPtr(HtCaptio n)
Else
MyBase.WndProc( m)
End If
End Sub
If you want to click on another control, such as a panel, and move the
form, you can use similar code:

private void Panel1_MouseDow n(object sender, MouseEventArgs e)
{
const uint WM_SYSCOMMAND = 0x0112;
const uint SC_MOVE = 0xF010;
const int HtCaption = 2;

pnlAdmin.Captur e = false;

SendMessage(thi s.Handle, WM_SYSCOMMAND, new IntPtr(SC_MOVE +
HtCaption),new IntPtr(0));
}
Hope this helps

Jun 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3887
by: Matt | last post by:
Is it possible to post form data and open an invisible window? For example, in page1.as <form action="page2.asp" method="POST" It will post the form data from page1.asp to the server, and open page2.asp. But I dont want to make page2.asp invisible. Any ideas?? Is it possible? Please advise. Thanks!!
0
1190
by: Dave L | last post by:
I want to create, via inheritance, my own UI control and use it in place of the stock .NET control in order to make system wide changes easily. For instance, I would inherit from Forms.Button and make a new class MyButton. My app would then use MyButton everywhere instead of Forms.Button. If I wanted a new look-and-feel, I could override the...
18
1501
by: rcamarda | last post by:
I think cursors might help me, but I'm not sure. I'm looking for ideas on how to solve a problem I have. Consider two tables, one table contains student information (very wide 100 fields) , the other historical changes of the student information, (narrow, just fields that record changes). As an example Table one has STUDENT_ID,...
5
6237
by: Prabhat | last post by:
Hi All, My website is hosted with the ISP and recently I have modified my Global.asa file for the ASP application. So I think we need to restart the World Wide Web Publishing Service so that the changes in the Global.asa will take effect. I think it will be difficult for the ISP to restart the Service as there many applications will be...
8
1118
by: Brett | last post by:
I have a button on a form. I've changed its text to "Exitl". However, when I run the app, the button text is "Exit". How could that happen? It's the only form in this app. I also have the timer on this form set for 2 second intervals. However, the timer constantly fires. I use to have it set at .2 seconds. Seems the old form is...
4
3329
by: gsb58 | last post by:
Hi! On a form I have a calendar. The form is rezised to 1024x768 (Don't worry - this is a training case) when loaded. Now I want to center the calendar on the form so that its edges are equally far from the upper, right, left and bottom borders of the form. I understand I must use the location property, am I right?
7
2314
by: greg.merideth | last post by:
I inherited a vs2003 project which I've converted into vs2005 to run under .net 2.0. The conversion was fine and the project compiles and runs just fine until today. A user called me up asking why they cannot see the bottom of the form anymore (it's a fixed height form). I opened the project again and looked at the form and sure enough,...
0
1153
by: Jerry Spence1 | last post by:
I have a rather wierd problem. Maybe I'm going about this the wrong way. My main application boots up OK and I have the main form WindowState set to Maximised. When the user clicks on an menu opion , I draw an Options Form. I have defined the height and width and have buttons and other controls on it. The Save and Cancel buttons are, as...
6
9978
tdw
by: tdw | last post by:
the View Orders form in my Access database has a Print button on it. It has other buttons too, like Edit etc. These buttons used to be at the bottom of the form laid out horizontally, but this was causing the form to be just long enough vertically that some people when viewing it on their screen would have to scroll up or down to see the top or...
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.