Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C# Programming

C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-08-2007, 10:12 AM
McMillan0520 McMillan0520 is offline
Newbie
 
Join Date: Aug 2007
Posts: 4
Rep Power: 0
McMillan0520 is on a distinguished road
Question Custom Control

I have made a custom control using c# and I have it in a project with another custom control. I include the compiled dllinto another project, but the BitmapButton is not visible (it seems it's not compiling). I don't know about the other control, because it wasn't made by me.

Here is the code of BitMapButton:
Code:
/*
 * Created by SharpDevelop.
 * User: MateuszJ
 * Date: 2007-08-07
 * Time: 22:36
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace Multitool.Controls
{
	/// <summary>
	/// Description of BitmapButton.
	/// </summary>
	public partial class BitmapButton : UserControl
	{
		public BitmapButton()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		
        Image backgroundImage, pressedImage;
        bool pressed = false;

        // Property for the background image to be drawn behind the button text.
        public Image BackgroundImage
        {
            get
            {
                return this.backgroundImage;
            }
            set
            {
                this.backgroundImage = value;
            }
        }

        // Property for the background image to be drawn behind the button text when
        // the button is pressed.
        public Image PressedImage
        {
            get
            {
                return this.pressedImage;
            }
            set
            {
                this.pressedImage = value;
            }
        }

        // When the mouse button is pressed, set the "pressed" flag to true 
        // and invalidate the form to cause a repaint.  The .NET Compact Framework 
        // sets the mouse capture automatically.
        protected override void OnMouseDown(MouseEventArgs e)
        {
            this.pressed = true;
            this.Invalidate();
            base.OnMouseDown (e);
        }

        // When the mouse is released, reset the "pressed" flag 
        // and invalidate to redraw the button in the unpressed state.
        protected override void OnMouseUp(MouseEventArgs e)
        {
            this.pressed = false;
            this.Invalidate();
            base.OnMouseUp (e);
        }

        // Override the OnPaint method to draw the background image and the text.
        protected override void OnPaint(PaintEventArgs e)
        {
            if(this.pressed && this.pressedImage != null)
                e.Graphics.DrawImage(this.pressedImage, 0, 0);
            else
                e.Graphics.DrawImage(this.backgroundImage, 0, 0);

            // Draw the text if there is any.
            if(this.Text.Length > 0)
            {
                SizeF size = e.Graphics.MeasureString(this.Text, this.Font);

                // Center the text inside the client area of the PictureButton.
                e.Graphics.DrawString(this.Text,
                    this.Font,
                    new SolidBrush(this.ForeColor),
                    (this.ClientSize.Width - size.Width) / 2,
                    (this.ClientSize.Height - size.Height) / 2);
            }

            // Draw a border around the outside of the 
            // control to look like Pocket PC buttons.
            e.Graphics.DrawRectangle(new Pen(Color.Black), 0, 0, 
                this.ClientSize.Width - 1, this.ClientSize.Height - 1);

            base.OnPaint(e);
        }
    
}
	}
and here is the code of the other control:
Code:
/*
 * Created by SharpDevelop.
 * User: MarcinS
 * Date: 2006-07-13
 * Time: 20:49
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace Multitool.Controls
{
	/// <summary>
	/// Description of ColorProgressBarWithText.
	/// </summary>
	public partial class ColorProgressBarWithText
	{
		public ColorProgressBarWithText()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		void ColorProgressBarWithTextPaint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			BackColor = this.Parent.BackColor;
  
			//brzegi
			Pen cien = new Pen(SystemColors.ControlDark);
			Pen swiatlo = new Pen(SystemColors.ControlLightLight);
			e.Graphics.DrawLine(cien,0,Height-1,0,0);
			e.Graphics.DrawLine(cien,0,0,Width-1,0);
			e.Graphics.DrawLine(swiatlo,Width-1,0,Width-1,Height-1);
			e.Graphics.DrawLine(swiatlo,Width-1,Height-1,0,Height-1);
			Bitmap bufor = new Bitmap(Width,Height);
			Graphics g = Graphics.FromImage(bufor);
			BackColor = this.Parent.BackColor;
			
			const int margines = 2;
			int stepwidth = 2*Height/3;
			double procenty = 0;
			if (Maximum>Minimum) procenty = (Value-Minimum)/(double)(Maximum-Minimum);
			int szerokosc = (int)Math.Round( procenty*(Width-2*margines-1));
			for (int i=margines;i<margines+szerokosc;i++) 
			{
			if (!Smooth && ((i%stepwidth)>0) && (i%stepwidth<margines+1)) continue;
			g.DrawLine(new Pen(ObliczKolor(i)), i,margines,i,Height-margines-1);
			
			}
			e.Graphics.DrawImage(bufor,0,0);
		}
		private Color ObliczKolor(int i)
		{
		if (i<0 || i>Width) throw new
			Exception("Zly parametr i");
		return Color.FromArgb(
		ColorBegin.R+i*(ColorEnd.R-ColorBegin.R)/Width,
		ColorBegin.G+i*(ColorEnd.G-ColorBegin.G)/Width,
		ColorBegin.B+i*(ColorEnd.B-ColorBegin.B)/Width);
		}
		public void PerformStep()
 		{
  			Value+=Step;
 		}
		#region Wlasnosci
			private int _Minimum = 0;
			private int _Maximum = 100;
			private int _Value = 0;
			private int _Step = 10;
			private Color _ColorBegin = Color.Yellow;
			private Color _ColorEnd = Color.Red;
			private bool _Smooth;
			private string _TextOn;
			
			public int Minimum 
			{ 
				get 
				{
					return _Minimum;
				}
				set 
				{
			   		if (value>_Maximum) 
			   			value = _Maximum;
			   		_Minimum = value;
			  		 Refresh(); 
				}
			}
			public int Maximum
			{
				get 
				{
					return _Maximum;
				}
				set 
				{
					if (value<_Minimum) 
						value = _Minimum;
					_Maximum = value;
					Refresh(); 
				}
			}
			public int Value 
			{
				get 
				{
					return _Value;
				}
				set 
				{
					if (value<_Minimum) 
						value = _Minimum;
					if (value>_Maximum) value = _Maximum;
						_Value = value;
					OnValueChanged(this,new EventArgs(),Value);
					Refresh(); 
				}
			}
			public int Step 
			{
				get 
				{
					return _Step;
				}
				set 
				{
					_Step = value;
				}
			}
			public Color ColorBegin 
			{
				get 
				{
					return _ColorBegin;
				}
				set 
				{
					_ColorBegin = value;
					Refresh(); 
				}
			}
			public Color ColorEnd 
			{
				get 
				{
					return _ColorEnd;
				}
				set 
				{
					_ColorEnd = value;
					Refresh(); 
				}
			}
			public bool Smooth 
			{
				get 
				{
					return _Smooth;
				}
				set 
				{
					_Smooth = value;
					Refresh(); 
				}
			}
			public string TextOn 
			{
				get 
				{
					return _TextOn;
				}
				set 
				{
					_TextOn = value;
					Refresh(); 
				}
			}
			
		#endregion
		#region Zdarzenie ValueChanged
			public delegate void ValueChangedEventHandler( object sender, System.EventArgs e, int _value);
		
			[Category("Behavior"), Description( "Zachodzi, gdy zmienia się własność Value.")]
			public event ValueChangedEventHandler ValueChanged;
		
			protected virtual void OnValueChanged( object sender, System.EventArgs e, int _value)
			{
				if (ValueChanged!=null)
				ValueChanged(this,e,_value);
			}
		#endregion
		
		void Refr(object sender, System.EventArgs e)
		{
			Refresh();
		}
	}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
website control panel monsurvey1 Introductions 5 01-26-2007 05:22 AM
Standards without control? martinig General Programming 3 01-18-2007 09:57 AM
Creating a Custom Cursor ahsan16 Tutorials, Classes and Code 2 01-13-2007 05:03 PM
Custom control properties Ronin C# Programming 1 09-15-2006 03:17 PM


All times are GMT -5. The time now is 10:17 AM.

Contest Stats

John ........ 203.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 63%

Ads