NET User Interfaces in Csharp Windows Forms and Custom Controls [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

NET User Interfaces in Csharp Windows Forms and Custom Controls [Electronic resources] - نسخه متنی

Matthew MacDonald

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید













































Graphics and Painting



Controls provide a variety of events and properties related to painting (Table 3-6). You'll find information about how to take control of these details and draw your own custom controls in the GDI+ chapters later in this book.













Table 3-6: Graphics-Related Members


MemberDescription










BackgroundImage



Allows you to show a picture in the background of a control.










Image (or ImageList and ImageIndex)



These properties aren't a part of the basic Control class, but they do appear in many common controls, including labels, buttons, check boxes, and radio buttons. It allows you to insert a picture alongside or instead of text, as shown in Chapter 6.










ImageAlign



Allows you to align a picture to any side or corner. It's not a part of the basic Control class, but it is found in many common controls.










ResizeRedraw



Indicates whether the control should automatically redraw itself when its size changes. The default is true.










CreateGraphics()



Creates a System.Drawing.Graphics object for the control (otherwise known as a device context). Used for custom drawing, as explained in Chapter 12.










Invalidate() and Refresh()



Triggers a repaint of the control.










Paint event



Occurs when the control is redrawn. Provides the device context, allowing you to perform some custom GDI+ drawing.










Resize event



Occurs when the control is resized, just before redrawing takes place.







You can create an Image object using the static Image.FromFile() method, which reads a standard bitmap format (like a BMP, GIF, JPEG, or PNG file).



button1.Image = Image.FromFile(Application.StartupPath + "\\mypic.bmp");


The Image class provides its own set of properties and methods. Some of the most interesting include RotateFlip(), which changes the picture orientation by rotating or inverting it, and GetThumbnailImage(), which returns an image object of the specified size that condenses the information from the original Image.




Image myImage, myThumbnail;
myImage = Image.FromFile(Application.StartupPath + "\\mypic.bmp");
// Rotate by 270 degrees and flip about the Y-axis.
myImage.RotateFlip(RotateFlipType.Rotate270FlipY);
// Create a 100 x 100 pixel thumbnail.
myThumbnail = myImage.GetThumbnailImage(100, 100, null, null);


Figure 3-9 shows common controls with embedded pictures. These can be added using the thoughtfully included Image and ImageAlign properties. However, if you place an image over a portion of the control text, the text will overwrite the image. No word wrapping is provided.




Figure 3-9: Common control picture support




/ 142