offline
- mandrake
- Građanin
- Pridružio: 14 Feb 2004
- Poruke: 142
- Gde živiš: Ruma, Vojvodina
|
Poslacu vam na email jedan objekat da vidite na koji nacin sam radio. Takodje cu postaviti i jedan deo koda za one koji zele da vide pre nego sto se prikljuce, a i ujedno da vide na kakav nacin sa uradio par stvari. Kasnije cemo se dogovoriti, ako zelite da pomognete, koje ce te objekte raditi.
#define GNU
#if GNU
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.ComponentModel;
using System.Windows.Forms;
namespace iSCG.Windows.Forms.Button
{
#region DELEGATE
//public delegate void ImageChangedEvent(object sender, System.EventArgs e);
#endregion
#region ENUM
/// <summary>
/// Enumeration for button state. There are five types: Normal, Over, Down, Focused and Disabled.
/// </summary>
public enum ButtonStates
{
/// <summary>Normal button state.</summary>
Normal,
/// <summary>Over button state.</summary>
Over,
/// <summary>Down button state.</summary>
Down,
/// <summary>Focused button state.</summary>
Focused,
/// <summary>Disabled button state.</summary>
Disable
}
/// <summary>
/// Enumeration for button type. There are three types: Image only, Image with Text and Text only.
/// </summary>
public enum ButtonType
{
/// <summary>Button with image only.</summary>
Image,
/// <summary>Button with text and image.</summary>
TextImage,
/// <summary>Button with text only.</summary>
Text
}
#endregion
/// <summary>
/// iSCG.Windows.Forms.Button object.
/// </summary>
public class SButton : System.Windows.Forms.Control
{
#region DEFAULT
/// <summary>
/// Declare new button object.
/// </summary>
public SButton()
{
// Create SButton
}
#endregion
#region EVENTS
//public event ImageChangedEvent ImageChanged;
#endregion
#region PRIVATE
private Image _normalImage;
private Image _overImage;
private Image _downImage;
private ButtonStates _buttonState;
private ButtonType _buttonType;
private string _buttonText;
private bool _focusRect = false;
private int _ddWidth = 12;
#endregion
#region PUBLIC
/// <summary>
/// Button text. Used only if you select Text or TextImage button type.
/// </summary>
public string ButtonText
{
get { return _buttonText; }
set { _buttonText = value; }
}
/// <summary>
/// Destination to image on your disk or image index in ImageList (Normal State).
/// </summary>
/// <example>Image.FromFile(@"skins\def\but\normal.png")</example>
public Image NormalImage
{
get { return _normalImage; }
set { _normalImage = value; DrawButton(this.CreateGraphics(), true); }
}
/// <summary>
/// Destination to image on your disk or image index in ImageList (Over State).
/// </summary>
/// <example>Image.FromFile(@"skins\def\but\over.png")</example>
public Image OverImage
{
get { return _overImage; }
set { _overImage = value; DrawButton(this.CreateGraphics(), true); }
}
/// <summary>
/// Destination to image on your disk or image index in ImageList (Down State).
/// </summary>
/// <example>Image.FromFile(@"skins\def\but\down.png")</example>
public Image DownImage
{
get { return _downImage; }
set { _downImage = value; DrawButton(this.CreateGraphics(), true); }
}
/// <summary>
/// Choose beetween five statets : Normal, Over, Down, Focused and Disabled.
/// </summary>
public ButtonStates SButtonState
{
get { return _buttonState; }
set { _buttonState = value; }
}
/// <summary>
/// Choose between three types: Image only, Image with Text and Text only.
/// </summary>
public ButtonType SButtonType
{
get { return _buttonType; }
set { _buttonType = value; }
}
/// <summary>
/// Get or Set focus rect on button when you got focus on it. Bool value.
/// </summary>
public bool FocusRect
{
get { return _focusRect; }
set { _focusRect = value; }
}
#endregion
#region OVERRIDE
/// <summary>
/// Detect when user press press laft muse button.
/// </summary>
/// <param name="e"></param>
protected override void OnMouseDown(MouseEventArgs e)
{
_buttonState = ButtonStates.Down;
DrawButton(this.CreateGraphics(), true);
base.OnMouseDown (e);
}
/// <summary>
/// Detect when user move mouse cursor over the button.
/// </summary>
/// <param name="e"></param>
protected override void OnMouseMove(MouseEventArgs e)
{
_buttonState = ButtonStates.Over;
DrawButton(this.CreateGraphics(), true);
base.OnMouseMove (e);
}
/// <summary>
/// Detect when user leave button with mouse cursor.
/// </summary>
/// <param name="e"></param>
protected override void OnMouseLeave(EventArgs e)
{
_buttonState = ButtonStates.Normal;
DrawButton(this.CreateGraphics(), true);
base.OnMouseLeave (e);
}
/// <summary>
/// Detect When user release mouse button.
/// </summary>
/// <param name="e"></param>
protected override void OnMouseUp(MouseEventArgs e)
{
_buttonState = ButtonStates.Over;
DrawButton(this.CreateGraphics(), true);
base.OnMouseUp (e);
}
/// <summary>
/// On paint. Default override for painting object.
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
_buttonState = ButtonStates.Normal;
DrawButton(this.CreateGraphics(), true);
base.OnPaint (e);
}
/// <summary>
/// Detect when user change size of the button.
/// </summary>
/// <param name="e"></param>
protected override void OnSizeChanged(EventArgs e)
{
_buttonState = ButtonStates.Normal;
DrawButton(this.CreateGraphics(), true);
base.OnSizeChanged (e);
}
/// <summary>
/// Detect when user set focus on button.
/// </summary>
/// <param name="e"></param>
protected override void OnGotFocus(EventArgs e)
{
_buttonState = ButtonStates.Over;
DrawButton(this.CreateGraphics(), true);
base.OnGotFocus (e);
}
/// <summary>
/// Detect when user lost focus on button.
/// </summary>
/// <param name="e"></param>
protected override void OnLostFocus(EventArgs e)
{
_buttonState = ButtonStates.Normal;
DrawButton(this.CreateGraphics(), true);
base.OnLostFocus (e);
}
#endregion
#region DRAW BUTTON INTERFACE
void DrawButton(Graphics g, bool Refresh)
{
if (!Refresh)
{
return;
}
g.Clear(this.BackColor);
Rectangle size = new Rectangle(0, 0, this.Width, this.Height);
System.Drawing.Brush _brush = new SolidBrush(Color.WhiteSmoke);
float _x = (float)((this.Width / 2) - (_buttonText.Length / 2));
float _y = (float)((this.Height / 2) - 4.25);
switch(_buttonType)
{
case ButtonType.Image:
switch(_buttonState)
{
case ButtonStates.Normal:
g.DrawImage(_normalImage, size);
break;
case ButtonStates.Down:
g.DrawImage(_downImage, size);
break;
case ButtonStates.Over:
g.DrawImage(_overImage, size);
break;
case ButtonStates.Disable:
ControlPaint.DrawImageDisabled(g, _normalImage, 0, 0, this.BackColor);
break;
}
break;
case ButtonType.Text:
switch(_buttonState)
{
case ButtonStates.Normal:
g.DrawString(_buttonText, new System.Drawing.Font("Arial", 8.5f), _brush, _x, _y);
break;
case ButtonStates.Down:
g.DrawImage(_downImage, size);
break;
case ButtonStates.Over:
g.DrawImage(_overImage, size);
break;
case ButtonStates.Disable:
ControlPaint.DrawImageDisabled(g, _normalImage, 0, 0, this.BackColor);
break;
}
break;
case ButtonType.TextImage:
switch(_buttonState)
{
case ButtonStates.Normal:
g.DrawImage(_normalImage, size);
break;
case ButtonStates.Down:
g.DrawImage(_downImage, size);
break;
case ButtonStates.Over:
g.DrawImage(_overImage, size);
break;
case ButtonStates.Disable:
ControlPaint.DrawImageDisabled(g, _normalImage, 0, 0, this.BackColor);
break;
}
break;
}
if (_focusRect)
{
Rectangle fr = size;
fr.Inflate(new Size(-3, -3));
fr.Width -= (_buttonState == ButtonStates.Focused) ? _ddWidth : 0;
ControlPaint.DrawFocusRectangle(g, fr);
}
}
#endregion
}
}
#endif
Ovaj kod jos nije zavrsen jer mu fali kreiranje Dugmeta sa tekstom i Dugmeta sa slikom i tekstom. Sve ostalo radi. Vidite formu projekta. Na taj nacin sam radio vecinu objekata.
|