Although I enjoy reading a lot, this is my very first attempt at writing (and what? "A Blog"). I don't know the basics of writing, so I take for granted that mistakes are ignored ( Better if you comment your heart out).
This post is related to programming a PictureBox object to rotate around another PictureBox object. This is an idea improved upon by me ( The original one is posted by +Rahul Jayant . Here is the link).
Let's now start the fun:-
We are going to use Visual Studio 2010 and C# ( Although I personally prefer VB.net). Steps are as follows :-
1) Create a new project and name it TestDemo (You can name it whatever you want).
2) Set the size of the form (should be Form1) to 800 x 800.
3) Insert two PictureBox.
Adjust the Location property
First PictureBox : 200,200
Second PictureBox : 500,300
Adjust the size property
First PictureBox : 300,300
Second PictureBox : 100,100
4) Download the image below and save to any location of your choice.
Add the following references
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Drawing.Drawing2D;
Now in the Form1_Load event add the following code
Bitmap mypicture = new Bitmap("C:\\users\\azad\\desktop\\globe.png");
mypicture.MakeTransparent(Color.Black);
this.pictureBox1.Image = mypicture;
this.pictureBox2.Image = mypicture;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
The path of the file should be adjusted to the downloaded image's path
Add the following function
void circlepath(int radius, Control ctrl)
{
GraphicsPath MyPath = new GraphicsPath();
for (double i = 0.0; i < 360.0; i += 0.1)
{
double angle = i * System.Math.PI / 180;
int x = (int)(radius + radius * System.Math.Cos(angle));
int y = (int)(radius + radius * System.Math.Sin(angle));
MyPath.AddLine(new Point(x, y), new Point(x, y));
}
MyPath.CloseFigure();
ctrl.Region = new Region(MyPath);
MyPath.Dispose();
}
5) Add a button and double click on it to open the code editor for the click event of the button and add the following code to it :
double radius = 200;
circlepath(150, this.pictureBox1);
circlepath(50, this.pictureBox2);
for (double i = 0.0; i < 360.0; i += 0.1)
{
double angle = i * System.Math.PI / 180;
int x = (int)(300 + radius * System.Math.Cos(angle));
int y = (int)(300 + radius * System.Math.Sin(angle));
pictureBox4.SetBounds(x, y, 100, 100);
Thread.Sleep(1);
And now we are ready to test our code. Hit F5 to run and see the magic. In case of any difficulty just leave a comment and I shall reply to you at the earliest.
Thank you for reading my blog. Any idea or suggestion is heartily welcome.
This post is related to programming a PictureBox object to rotate around another PictureBox object. This is an idea improved upon by me ( The original one is posted by +Rahul Jayant . Here is the link).
Let's now start the fun:-
We are going to use Visual Studio 2010 and C# ( Although I personally prefer VB.net). Steps are as follows :-
1) Create a new project and name it TestDemo (You can name it whatever you want).
2) Set the size of the form (should be Form1) to 800 x 800.
3) Insert two PictureBox.
Adjust the Location property
First PictureBox : 200,200
Second PictureBox : 500,300
Adjust the size property
First PictureBox : 300,300
Second PictureBox : 100,100
4) Download the image below and save to any location of your choice.
Add the following references
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Drawing.Drawing2D;
Now in the Form1_Load event add the following code
Bitmap mypicture = new Bitmap("C:\\users\\azad\\desktop\\globe.png");
mypicture.MakeTransparent(Color.Black);
this.pictureBox1.Image = mypicture;
this.pictureBox2.Image = mypicture;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
The path of the file should be adjusted to the downloaded image's path
Add the following function
void circlepath(int radius, Control ctrl)
{
GraphicsPath MyPath = new GraphicsPath();
for (double i = 0.0; i < 360.0; i += 0.1)
{
double angle = i * System.Math.PI / 180;
int x = (int)(radius + radius * System.Math.Cos(angle));
int y = (int)(radius + radius * System.Math.Sin(angle));
MyPath.AddLine(new Point(x, y), new Point(x, y));
}
MyPath.CloseFigure();
ctrl.Region = new Region(MyPath);
MyPath.Dispose();
}
5) Add a button and double click on it to open the code editor for the click event of the button and add the following code to it :
double radius = 200;
circlepath(150, this.pictureBox1);
circlepath(50, this.pictureBox2);
for (double i = 0.0; i < 360.0; i += 0.1)
{
double angle = i * System.Math.PI / 180;
int x = (int)(300 + radius * System.Math.Cos(angle));
int y = (int)(300 + radius * System.Math.Sin(angle));
pictureBox4.SetBounds(x, y, 100, 100);
Thread.Sleep(1);
And now we are ready to test our code. Hit F5 to run and see the magic. In case of any difficulty just leave a comment and I shall reply to you at the earliest.
Thank you for reading my blog. Any idea or suggestion is heartily welcome.

Comments
Post a Comment