| | | | |   |
 
 
 
Tut: How to extend the client area in C# /w WPF
 
Reply to this topic Start new topic
bns06
post Apr 27 2008, 02:49 PM
Post #1


Genius
Group Icon

Group: Member
Posts: 1,673
Joined: 15-July 07
From: England, Ashton
Member No.: 17,296
OS: Windows 7 70xx



This is a tutorial for extending glass into the client area in C# with WPF

1. Start with going "file" then "new project", slect WPF Appliation and click ok.

2. Then download the DWM wrapper .dll here. Then click "project" and then "add reference". Navigate to browse along the tab bar and find the place were you have put the .dll and double click it. It will then be added to the references but dont move the .dll till you have done at least 1 compile.

3. Then add "using GlassLib;" like shown by simply typeing it in. grimace.png Attached File  usingglasslib.jpg ( 150.33K ) Number of downloads: 100


4. Next go into the .xaml, you will see "Title="Window1"" if you havent renamed it already wink.png Then after that type "Loaded=" and then a menu will appear click "<New Event Handler>". After this you will have what is shown Attached File  Window_Loaded.jpg ( 171.28K ) Number of downloads: 109


5. Then pop into the .xaml.cs and paste this inbetween the brackets that will have been created >>Attached File  Bracket.jpg ( 176.31K ) Number of downloads: 72

This is what needs pasteing
CODE
Dwm.Glass[this].Enabled = true;
Thickness foo = new Thickness(5, 30, 5, 20);
Dwm.Glass[this].Margins = foo;

In this code the margins 5, 30, 5, 20 are Left, Right, Top, Bottom.
The code will then look like this >>Attached File  DWM.jpg ( 180.71K ) Number of downloads: 68


This is the end of the tutorial for implementing glass. If you would like to know how to extend the area that can be dragged into the glass area... read on...


6. Go into the .xaml design and create a lable that covers the whole of the glass area, then remove the text in it that will by default say "label".

7. Then go into the .xaml area and find the "label" line. Replace what it is on the label line with
CODE
<Label MouseDown="Extend_Grabber" MouseDoubleClick="Extend_MouseDoubleClick" />

It should then look like this >> Attached File  grabber_xaml.jpg ( 176.08K ) Number of downloads: 65


8. Right click on "Extend_Grabber " then click "navigate to even handler". You will be then be taken to the .xaml.cs code and inside the brackets copy and paste this
CODE
try
{
DragMove();
}
catch (System.InvalidOperationException)
{
return;
}

It should then look like this >> Attached File  grabber_cs.jpg ( 162.67K ) Number of downloads: 51
]

9. Next go back to the .xaml and right click "Extend_MouseDoubleClick" on the label line, then click "navigate to event handler". Again you will be taken to the .cs code and inside the brackets copy and paste this
CODE
if (this.WindowState == WindowState.Maximized)
{
this.WindowState = WindowState.Normal;
}
else
{
this.WindowState = WindowState.Maximized;
}

It should then look like this >>Attached File  double_click_cs.jpg ( 176.1K ) Number of downloads: 98


10. Then go back to the .xaml design and drag the label back to the full size.
11. Give yourself a pat on the back you've done it grimace.png

Note:Remember to change the margins of the glass to suit your application wink.png

Credits to Panda X for telling me how to do it, then i wrote the tut.


--------------------
Go to the top of the page
 
+Quote Post
bns06
post May 16 2008, 05:48 PM
Post #2


Genius
Group Icon

Group: Member
Posts: 1,673
Joined: 15-July 07
From: England, Ashton
Member No.: 17,296
OS: Windows 7 70xx



Bump... Sorry but someone must have liked this xD


--------------------
Go to the top of the page
 
+Quote Post
ChristopherT
post May 24 2008, 01:29 AM
Post #3


Member
Group Icon

Group: Member
Posts: 50
Joined: 29-June 07
From: Pittsburgh, PA
Member No.: 16,700
OS: Windows 7 Beta 1, Mac OS X 10.5.6



I do. grimace.png It works great and it is my first piece of WPF coding in C# grimace.png


--------------------
Go to the top of the page
 
+Quote Post
bns06
post May 24 2008, 12:29 PM
Post #4


Genius
Group Icon

Group: Member
Posts: 1,673
Joined: 15-July 07
From: England, Ashton
Member No.: 17,296
OS: Windows 7 70xx



Yay some one exciting.png

Glad to help big_smile.png


--------------------
Go to the top of the page
 
+Quote Post
Zanpluktou
post Jun 10 2008, 08:03 PM
Post #5


Member
Group Icon

Group: Member
Posts: 83
Joined: 9-October 07
From: Houston, Texas USA
Member No.: 19,749
OS: Windows Vista Ultimate x64 SP1



This is a great tutorial. I was wondering however if this is the same steps in Visual Basic?
Go to the top of the page
 
+Quote Post
bns06
post Jun 10 2008, 08:06 PM
Post #6


Genius
Group Icon

Group: Member
Posts: 1,673
Joined: 15-July 07
From: England, Ashton
Member No.: 17,296
OS: Windows 7 70xx



CODE
Imports GlassLib


CODE
Dwm.Glass(Me).Enabled = True
Dim foo As New Thickness(5, 30, 5, 20)
Dwm.Glass(Me).Margins = foo


Using them piecs of code instead wink.png


--------------------
Go to the top of the page
 
+Quote Post
Zanpluktou
post Jun 11 2008, 03:33 AM
Post #7


Member
Group Icon

Group: Member
Posts: 83
Joined: 9-October 07
From: Houston, Texas USA
Member No.: 19,749
OS: Windows Vista Ultimate x64 SP1



Awesome! Worked like a charm. Thanks. I have other VB questions but I'll save that for another time. However I do have one more question. For the margins, what should I use if I want the program to be full glass with no black. I'm using 1000 for each right now and it works but not sure if it will for higher resolutions. Using 1680x1050.

This post has been edited by Zanpluktou: Jun 11 2008, 03:33 AM
Go to the top of the page
 
+Quote Post
Ludacris
post Sep 1 2008, 04:12 PM
Post #8


g0dl1k3
Group Icon

Group: News Poster
Posts: 3,762
Joined: 23-September 06
From: Vienna, Austria
Member No.: 4,502
OS: 6.1.7600



QUOTE (Zanpluktou @ Jun 11 2008, 05:33 AM) *
Awesome! Worked like a charm. Thanks. I have other VB questions but I'll save that for another time. However I do have one more question. For the margins, what should I use if I want the program to be full glass with no black. I'm using 1000 for each right now and it works but not sure if it will for higher resolutions. Using 1680x1050.



bump:

-1 black_heart.png


--------------------

Ready for future?
Go to the top of the page
 
+Quote Post
bns06
post Sep 1 2008, 04:16 PM
Post #9


Genius
Group Icon

Group: Member
Posts: 1,673
Joined: 15-July 07
From: England, Ashton
Member No.: 17,296
OS: Windows 7 70xx



-1 for full glass borders and the code in VB is...

Imports GlassLib

and...

Dwm.Glass(Me).Enabled = True
Dim foo As New Thickness(5, 30, 5, 20)
Dwm.Glass(Me).Margins = foo


--------------------
Go to the top of the page
 
+Quote Post

 Reply to this topic Start new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:
 



RSS Lo-Fi Version Time is now: 9th February 2010 - 03:37 PM
  joejoe © 2006-2010 All Rights Reserved