joejoe.org Community: Tut: How to extend the client area in C# /w WPF - joejoe.org Community

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Tut: How to extend the client area in C# /w WPF

#1 User is offline   bns06 Icon

  • Genius
  • Icon
  • Group: Member
  • Posts: 1,673
  • Joined: 15-July 07
  • Gender:Male
  • Location:England, Ashton
  • OS: Windows 7 70xx

Posted 27 April 2008 - 02:49 PM

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: 105

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: 112

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: 77
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: 70

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: 69

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: 54]

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: 101

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.

#2 User is offline   bns06 Icon

  • Genius
  • Icon
  • Group: Member
  • Posts: 1,673
  • Joined: 15-July 07
  • Gender:Male
  • Location:England, Ashton
  • OS: Windows 7 70xx

Posted 16 May 2008 - 05:48 PM

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

#3 User is offline   ChristopherT Icon

  • Member
  • Icon
  • Group: Member
  • Posts: 50
  • Joined: 29-June 07
  • Gender:Male
  • Location:Pittsburgh, PA
  • Interests:Computers, HTML, Coding.
  • OS: Windows 7 Beta 1, Mac OS X 10.5.6

Posted 24 May 2008 - 01:29 AM

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

#4 User is offline   bns06 Icon

  • Genius
  • Icon
  • Group: Member
  • Posts: 1,673
  • Joined: 15-July 07
  • Gender:Male
  • Location:England, Ashton
  • OS: Windows 7 70xx

Posted 24 May 2008 - 12:29 PM

Yay some one exciting.png

Glad to help big_smile.png

#5 User is offline   Zanpluktou Icon

  • Member
  • Icon
  • Group: Member
  • Posts: 83
  • Joined: 09-October 07
  • Gender:Male
  • Location:Houston, Texas USA
  • OS: Windows Vista Ultimate x64 SP1

Posted 10 June 2008 - 08:03 PM

This is a great tutorial. I was wondering however if this is the same steps in Visual Basic?

#6 User is offline   bns06 Icon

  • Genius
  • Icon
  • Group: Member
  • Posts: 1,673
  • Joined: 15-July 07
  • Gender:Male
  • Location:England, Ashton
  • OS: Windows 7 70xx

Posted 10 June 2008 - 08:06 PM

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

#7 User is offline   Zanpluktou Icon

  • Member
  • Icon
  • Group: Member
  • Posts: 83
  • Joined: 09-October 07
  • Gender:Male
  • Location:Houston, Texas USA
  • OS: Windows Vista Ultimate x64 SP1

Posted 11 June 2008 - 03: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.

This post has been edited by Zanpluktou: 11 June 2008 - 03:33 AM


#8 User is offline   Ludacris Icon

  • g0dl1k3
  • Icon
  • Group: News Poster
  • Posts: 3,825
  • Joined: 23-September 06
  • Gender:Male
  • Location:Vienna, Austria
  • Interests:My GF, Reading,IT,...
  • OS: 6.1.7600

Posted 01 September 2008 - 04:12 PM

QUOTE (Zanpluktou @ Jun 11 2008, 05:33 AM) <{POST_SNAPBACK}>
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?

#9 User is offline   bns06 Icon

  • Genius
  • Icon
  • Group: Member
  • Posts: 1,673
  • Joined: 15-July 07
  • Gender:Male
  • Location:England, Ashton
  • OS: Windows 7 70xx

Posted 01 September 2008 - 04:16 PM

-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

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users