Windows Develop Bookmark and Share   
 index > Windows Forms Designer > rotating menu
 

rotating menu

It's possible that i can make a menu like this:


At the begining of my program?

Thanks, Gonzalo Díaz.
Gonzalo Díaz  Monday, May 25, 2009 2:59 AM
well i doubt native menu bar would let you do this. The closest you can get is to add a OpenGL/DirectX panel and create something similar to this. Either of them will let you create a 3-D view and do all the movements of the menu items.
Kavitesh Singh.
Kavitesh Singh  Tuesday, May 26, 2009 6:03 AM

Hi Gonzalo Díaz,

Based on your description and the action script you provided with, I find a similar implementation below:

Animation.cs, the file includes the animation logic:


internal class Animation

{

/// <summary>

/// Initialization

/// </summary>

/// <param name="form">the animation form</param>

/// <param name="timeInterval">the ticket amount for each move</param>

public Animation(Form form, int timeInterval)

{

_hx = form.ClientRectangle.Width / 2 - 20;

_r = 300;

form.MouseMove += new MouseEventHandler(form_MouseMove);

_timer.Interval = timeInterval;

_timer.Tick += new EventHandler(_timer_Tick);

}

/// <summary>

/// Add a control , save its information and initiallize it

/// </summary>

/// <param name="ctrl"></param>

public void AddControl(Control ctrl)

{

ControlState ctrlState = new ControlState();

ctrlState.Control = ctrl;

ctrlState.StartLocation = ctrl.Location;

ctrlState.StartSize = ctrl.Size;

ctrlState.StartColor = ctrl.ForeColor;

//Stop moving when the mouse is on the control and change the size of the control to alert user.

ctrl.MouseEnter += new EventHandler(ctrl_MouseEnter);

ctrl.MouseLeave += new EventHandler(ctrl_MouseLeave);

this._controls.Add(ctrlState);

}

private void ctrl_MouseEnter(object sender, EventArgs e)

{

_stopped = true;

Control ctrl = sender as Control;

ctrl.Size = Size.Round(new SizeF(ctrl.Width * FONT_CHANGE_MOUSE_ON, ctrl.Height * FONT_CHANGE_MOUSE_ON));

ctrl.Font = new Font(ctrl.Font.FontFamily, ctrl.Height * FONT_BUTTON_WIDTH__RATE);

}

private void ctrl_MouseLeave(object sender, EventArgs e)

{

_stopped = false;

Control ctrl = sender as Control;

ctrl.Size = Size.Round(new SizeF(ctrl.Width / FONT_CHANGE_MOUSE_ON, ctrl.Height / FONT_CHANGE_MOUSE_ON));

ctrl.Font = new Font(ctrl.Font.FontFamily, ctrl.Height * FONT_BUTTON_WIDTH__RATE);

}

/// <summary>

/// Start the animation.

/// </summary>

public void Start()

{

float angleUnit = (float)(2 * Math.PI / _controls.Count);

float initAngle = 0.0f;

foreach (ControlState ctrl in _controls)

{

ctrl.StartAngle = initAngle;

initAngle += angleUnit;

}

_timer.Start();

}

/// <summary>

/// Stop the animation

/// </summary>

public void Stop()

{

_timer.Stop();

}

public List<ControlState> Controls

{

get { return _controls; }

}

/// <summary>

/// Continue

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void _timer_Tick(object sender, EventArgs e)

{

foreach (ControlState ctrl in _controls)

{

Rotate(ctrl);

}

}

/// <summary>

/// Used to update the mouse position.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void form_MouseMove(object sender, MouseEventArgs e)

{

_mouseX = e.X;

}

/// <summary>

/// calculate speed

/// </summary>

/// <param name="num"></param>

/// <returns></returns>

private float Speed(int num)

{

return -(_mouseX - _hx)* 1.0f / num;

}

/// <summary>

/// rotate the control

/// </summary>

/// <param name="ctrlState"></param>

private void Rotate(ControlState ctrlState)

{

if (_stopped == false)

{

//Calculate the moving distance

_p += Speed(NUM);

_range = ((_p + ANGLE_OFFSET) * Math.PI) / 180;

_range += ctrlState.StartAngle;

//Canculate factors

int re1 = (int)((Math.Sin(_range)) * _r);

int re2 = (int)((Math.Cos(_range)) * _a);

SetControl(ctrlState, re1, re2);

}

}

/// <summary>

/// Set some properties of the control

/// </summary>

/// <param name="ctrlState">control information</param>

/// <param name="re1">factor 1</param>

/// <param name="re2">factor 2</param>

private void SetControl(ControlState ctrlState,int re1, int re2)

{

//Change the location

ctrlState.Control.Location = new Point(

ctrlState.StartLocation.X + re1 + ctrlState.StartSize.Width / 2 + LOCATION_OFFSET,

ctrlState.StartLocation.Y);

// Calculate change rate

float rate = (re2 + 70) * 1.0f / 100;

//Change color gradually

int r = (int)(ctrlState.StartColor.R + (ctrlState.Control.BackColor.R - ctrlState.StartColor.R) * (1 - rate));

int g = (int)(ctrlState.StartColor.G + (ctrlState.Control.BackColor.G - ctrlState.StartColor.G) * (1 - rate));

int b = (int)(ctrlState.StartColor.B + (ctrlState.Control.BackColor.B - ctrlState.StartColor.B) * (1 - rate));

ctrlState.Control.ForeColor = Color.FromArgb(1,r,g,b);

//Scale the control

ctrlState.Control.Size = Size.Round(new SizeF(ctrlState.StartSize.Width * rate, ctrlState.StartSize.Height * rate));

ctrlState.Control.Font = new Font(ctrlState.Control.Font.FontFamily, ctrlState.Control.Height * FONT_BUTTON_WIDTH__RATE);

}

private int _hx = 0;

private int _r = 0;

private int _a = 30;

private int _mouseX = 0;

private double _range = 0;

private float _p;

private bool _stopped = false;

private List<ControlState> _controls = new List<ControlState>();

private Timer _timer = new Timer();

private const int NUM = 200;

private const int ANGLE_OFFSET = 144;

private const float FONT_BUTTON_WIDTH__RATE = 40.0f / 137;

private const int LOCATION_OFFSET = 50;

private const float FONT_CHANGE_MOUSE_ON = 1.2f;

}

/// <summary>

/// Save the initial information of the control

/// </summary>

internal class ControlState

{

public Control Control { set; get; }

public Point StartLocation { set; get; }

public Size StartSize { set; get; }

public float StartAngle { set; get; }

public Color StartColor { set; get; }

}

To be continued �/span>


Please mark the replies as answers if they help and unmark if they don't.
Aland Li  Sunday, May 31, 2009 1:55 AM

Form1.cs, the file shows how to use Animation class:

public Form1()

{

InitializeComponent();

this.Init();

}

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.Button button3;

private System.Windows.Forms.Button button4;

private System.Windows.Forms.Button button5;

private Animation _manager = null;

private void Init()

{

this.button1 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.button3 = new System.Windows.Forms.Button();

this.button4 = new System.Windows.Forms.Button();

this.button5 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// button1

//

this.button1.BackColor = System.Drawing.Color.Black;

this.button1.FlatAppearance.BorderSize = 0;

this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;

this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

this.button1.ForeColor = System.Drawing.Color.White;

this.button1.Location = new System.Drawing.Point(12, 28);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(338, 61);

this.button1.TabIndex = 0;

this.button1.Text = "everything you need";

this.button1.UseVisualStyleBackColor = false;

//

// button2

//

this.button2.BackColor = System.Drawing.Color.Black;
this.button2.FlatAppearance.BorderSize = 0;

this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;

this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

this.button2.ForeColor = System.Drawing.Color.White;

this.button2.Location = new System.Drawing.Point(12, 138);

this.button2.Name = "button2";

this.button2.Size = new System.Drawing.Size(338, 61);

this.button2.TabIndex = 1;

this.button2.Text = "more than 1,000 tools";

this.button2.UseVisualStyleBackColor = false;

//

// button3

//

this.button3.BackColor = System.Drawing.Color.Black;
this.button3.FlatAppearance.BorderSize = 0;

this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;

this.button3.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

this.button3.ForeColor = System.Drawing.Color.White;

this.button3.Location = new System.Drawing.Point(12, 248);

this.button3.Name = "button3";

this.button3.Size = new System.Drawing.Size(338, 76);

this.button3.TabIndex = 2;

this.button3.Text = "www.microsoft.com";

this.button3.UseVisualStyleBackColor = false;

//

// button4

//

this.button4.Location = new System.Drawing.Point(497, 361);

this.button4.Name = "button4";

this.button4.Size = new System.Drawing.Size(75, 23);

this.button4.TabIndex = 3;

this.button4.Text = "Start";

this.button4.UseVisualStyleBackColor = true;

this.button4.Click += new System.EventHandler(this.button4_Click);

//

// button5

//

this.button5.Location = new System.Drawing.Point(599, 361);

this.button5.Name = "button5";

this.button5.Size = new System.Drawing.Size(75, 23);

this.button5.TabIndex = 4;

this.button5.Text = "Stop";

this.button5.UseVisualStyleBackColor = true;

this.button5.Click += new System.EventHandler(this.button5_Click);

//

// Form1

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(718, 529);

this.Controls.Add(this.button5);

this.Controls.Add(this.button4);

this.Controls.Add(this.button3);

this.Controls.Add(this.button2);

this.Controls.Add(this.button1);

this.Name = "Form1";

this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);

this.ResumeLayout(false);

}

private void Form1_Load(object sender, EventArgs e)

{

_manager = new Animation(this, 1);

_manager.AddControl(this.button1);

_manager.AddControl(this.button2);

_manager.AddControl(this.button3);

foreach (ControlState ctrl in _manager.Controls)

{

Button bt = ctrl.Control as Button;

if (bt != null)

{

bt.Click += new EventHandler(delegate(object buttonControl, EventArgs eArgs)

{

MessageBox.Show(bt.Text);

});

}

}

}

private void button4_Click(object sender, EventArgs e)

{

_manager.Start();

}

private void button5_Click(object sender, EventArgs e)

{

_manager.Stop();

}

Let me know if this helps.

Best regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't.
Aland Li  Sunday, May 31, 2009 1:55 AM

You can use google to search for other answers

Custom Search

More Threads

• How to set readonly for property with return value of collection.
• MasterPage : having trouble to control column width of the model matrix
• Resx design-time serialization
• Rich Text Box - Disable Selection
• Cannot open Designer
• multithread to richtextbox?
• problem with vscrollbar
• Not able to Override text property of label in derived class
• How to apply custom TypeConverter on collection item
• form designer compile error between 2003 & 2005