473,372 Members | 1,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Easy Question about SDK Code New

jm
I got the code below from the .NET SDK. I am still new to C# and I
don't understand how the code works. And by that I mean I don't
understand how the program knows to execute it. I can find no entry
point besides main. I cannot find an event that calls the code. It
is a simple GDI+ application. I just don't see how it ever executes.
I need nothing about the code itself, just how the thing "turns on."
I don't ever see OnPaint called anywhere. Thanks:
//-----------------------------------------------------------------------
// This file is part of the Microsoft .NET SDK Code Samples.
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//This source code is intended only as a supplement to Microsoft
//Development Tools and/or on-line documentation. See these other
//materials for detailed information regarding Microsoft code samples.
//
//THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//PARTICULAR PURPOSE.
//-----------------------------------------------------------------------
namespace Microsoft.Samples.WinForms.Cs.GDIPlus.GDIPBrushes {
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

public class BrushesSample : System.Windows.Forms.Form {
/// <summary>
/// Required designer variable.
/// </summary>+
private System.ComponentModel.Container components;

private System.Drawing.Brush backgroundBrush;

public BrushesSample() {

//
// Required for Windows Form Designer support
//
InitializeComponent();

this.SetStyle(System.Windows.Forms.ControlStyles.O paque,
true);

//Load the image to be used for the background from the
exe's resource fork
Image backgroundImage = new
Bitmap(Assembly.GetExecutingAssembly().GetManifest ResourceStream("colorbars.jpg"));

//Now create the brush we are going to use to paint the
background
backgroundBrush = new TextureBrush(backgroundImage);
}

protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;

g.SmoothingMode = SmoothingMode.AntiAlias;

//Fill the background use the texture brush
//and then apply a white wash
g.FillRectangle(backgroundBrush, ClientRectangle);
g.FillRectangle(new SolidBrush(Color.FromArgb(180,
Color.White)), ClientRectangle);

//Add a Red rectangle and a yellow one that overlaps it
g.FillRectangle(new SolidBrush(Color.Red), 20, 20, 50,
50);
g.FillRectangle(new SolidBrush(Color.FromArgb(180,
Color.Yellow)), 40, 40, 50, 50);

//Add a circle that is filled with a translucent hatch
HatchBrush hb = new HatchBrush(HatchStyle.ForwardDiagonal,
Color.Green, Color.FromArgb(100, Color.Yellow));
g.FillEllipse(hb, 250, 10, 100, 100);

//Now create a rectangle filled with a gradient brush
Rectangle r = new Rectangle(300, 250, 100, 100);
LinearGradientBrush lb = new LinearGradientBrush(r,
Color.Red, Color.Yellow,LinearGradientMode.BackwardDiagonal);
g.FillRectangle(lb, r);

//Now add a shape drawn with a path gradient brush
GraphicsPath path = new GraphicsPath(new Point[] {
new
Point(40, 140),
new
Point(275, 200),
new
Point(105, 225),
new
Point(190, 300),
new
Point(50, 350),
new
Point(20, 180),
},
new byte[] {

(byte)PathPointType.Start,

(byte)PathPointType.Bezier,

(byte)PathPointType.Bezier,

(byte)PathPointType.Bezier,

(byte)PathPointType.Line,

(byte)PathPointType.Line,
}
);

PathGradientBrush pgb = new PathGradientBrush(path);
pgb.SurroundColors = new Color[] {
Color.Green,
Color.Yellow,
Color.Red,
Color.Blue,
Color.Orange,
Color.White,
};

g.FillPath(pgb, path);

//Now add a simple rectangle that has been rotated
g.RotateTransform(-30);
g.FillRectangle(new SolidBrush(Color.SlateBlue), 100, 250,
75, 100);
g.ResetTransform();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing) {
base.Dispose(disposing);
components.Dispose();
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent () {
this.components = new System.ComponentModel.Container ();
this.Text = "GDI+ Brush Samples";
this.Size = new System.Drawing.Size(450, 400);
}

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main() {
Application.Run(new BrushesSample());
}
}
}
Nov 16 '05 #1
2 1297
"jm" <jo*************@yahoo.com> wrote in message news:c6**************************@posting.google.c om...
I got the code below from the .NET SDK. I am still new to C# and I
don't understand how the code works. And by that I mean I don't
understand how the program knows to execute it. I can find no entry
point besides main.
Main( ) is a perfectly good entry point, the application only needs
one, after all. :-)

Let's start there. It calls the Run method on Application (there's no
need to create an Application object because Run( ) is static) and
passes it a new BrushesSample. In doing so, it had to call the
BrushesSample( ) constructor to create an instance of Brushes-
Sample (and that default, parameterless constructor in turn calls
InitializeComponent( ) which assigns initial values to some,
in this case a small number of, inherited properties.)

What is BrushesSample? BrushesSample is a subclass of the
Form base class. BrushesSample just overrides some of the
virtual methods of Form, like OnPaint( ), with the custom function-
ality that BrushesSample requires.
I cannot find an event that calls the code.
Form is bristling with events, check the .NET Framework SDK
documentation for a listing (the following link in 1.1 should open
this in help, it's a long URL so you may need to correct it for
linewrap):

ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemWindowsFormsFormMembersTopic.htm

Application.Run( ) registered the "window class" (this goes
back to antiquated Win32 programming days, no need to
concern yourself with it) and a windows event handler to
dispatch windows message (WM_PAINT, etc.) to the
Managed Form subclass.

This may initially appear "disconnected," but the Form is
very much driven by the message-passing in Windows.
I don't ever see OnPaint called anywhere.


Whenever the user covers up a portion of the window
on the screen with another window, re-sizes it, minimizes
it and restores it; Windows sends the native event handler
method a WM_PAINT message. This message and the
client area that needs to get painted (invalidated) is all
processed deep within the Framework and then OnPaint
method gets called for you.

When getting started, the deep underpinnings aren't as
relevant as getting familiar with the many, many methods,
events and properties of Form (and the Controls you can
use on it), at least once you get over the initial cognitive
dissonance over the apparent disconnectness of event
driven UI programming.

We can all appreciate no longer having to write complex
switching logic and Windows message event handlers
anymore, .NET has taken us away from all of that. :-)
Derek Harmon
Nov 16 '05 #2
jm
"Derek Harmon" <lo*******@msn.com> wrote in message news:<#z**************@TK2MSFTNGP11.phx.gbl>...
"jm" <jo*************@yahoo.com> wrote in message news:c6**************************@posting.google.c om...
I got the code below from the .NET SDK. I am still new to C# and I
don't understand how the code works. And by that I mean I don't
understand how the program knows to execute it. I can find no entry
point besides main.


Main( ) is a perfectly good entry point, the application only needs
one, after all. :-)

Let's start there. It calls the Run method on Application (there's no
need to create an Application object because Run( ) is static) and
passes it a new BrushesSample. In doing so, it had to call the
BrushesSample( ) constructor to create an instance of Brushes-
Sample (and that default, parameterless constructor in turn calls
InitializeComponent( ) which assigns initial values to some,
in this case a small number of, inherited properties.)

What is BrushesSample? BrushesSample is a subclass of the
Form base class. BrushesSample just overrides some of the
virtual methods of Form, like OnPaint( ), with the custom function-
ality that BrushesSample requires.
I cannot find an event that calls the code.


Form is bristling with events, check the .NET Framework SDK
documentation for a listing (the following link in 1.1 should open
this in help, it's a long URL so you may need to correct it for
linewrap):

ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemWindowsFormsFormMembersTopic.htm

Application.Run( ) registered the "window class" (this goes
back to antiquated Win32 programming days, no need to
concern yourself with it) and a windows event handler to
dispatch windows message (WM_PAINT, etc.) to the
Managed Form subclass.

This may initially appear "disconnected," but the Form is
very much driven by the message-passing in Windows.
I don't ever see OnPaint called anywhere.


Whenever the user covers up a portion of the window
on the screen with another window, re-sizes it, minimizes
it and restores it; Windows sends the native event handler
method a WM_PAINT message. This message and the
client area that needs to get painted (invalidated) is all
processed deep within the Framework and then OnPaint
method gets called for you.

When getting started, the deep underpinnings aren't as
relevant as getting familiar with the many, many methods,
events and properties of Form (and the Controls you can
use on it), at least once you get over the initial cognitive
dissonance over the apparent disconnectness of event
driven UI programming.

We can all appreciate no longer having to write complex
switching logic and Windows message event handlers
anymore, .NET has taken us away from all of that. :-)
Derek Harmon

So, essentially, I override the method OnPaint which is always called
and therefore it painted.
Nov 16 '05 #3

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

Similar topics

6
by: JW | last post by:
I'm displaying product thumbnails with brief descriptions on web pages. Clicking on the product does a javascript popup with larger image and detailed description info passed to the javascript...
6
by: Nick Dreyer | last post by:
In VB.NET I would like to not have to create property get/set procedures for every class variable I want to expose to Excel VBA projects in COM builds. Can anyone tell me if that is possible, or...
3
by: Oliver Bryant | last post by:
I just finished developing a javascipt component allowing floating captions to appear over HTML elements. If anyone wants to check it out you can see specs and download it from...
4
by: I_have_nothing | last post by:
Hi! Is there any easy way to printf an integer in a way like 1,234,567? I know "%d" can be usd to print it as 1234567. Any type field in format specification can do that? Or any easy way to do...
10
by: Brian | last post by:
Hello all, I have an form to Enter a Name with letters from A to Z in buttons. When you click a button, it should append the text associated with that button to a text box. Instead of...
3
by: Jason | last post by:
I'm using asp.net to create a staff directory based on Active Directory, and I'm sure this is an easy question, but I can't seem to find anything about it in the newsgroups: I know it's possible...
14
by: google | last post by:
I am creating a new database for use within our company, that I'd like to make reasonably secure (short of a true server based solution). The back-end of a non-server based database seems to be...
409
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
8
by: Irene | last post by:
Hi, I have an MS Access Database with 1 Table containing about 2 million records in Unicode (diferent languages). I would like to export the Table to a Text file (CSV, Tab, etc.) Access...
20
by: raylopez99 | last post by:
Inspired by Chapter 8 of Albahari's excellent C#3.0 in a Nutshell (this book is amazing, you must get it if you have to buy but one C# book) as well as Appendix A of Jon Skeet's book, I am going...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.