//
//TODO: Add the constructor code here
//
bmp=gcnew Bitmap(300,300);
gr6=0.314/3;
rs=80;
rm=60;
rh=40;
centerX=150;
centerY=150;
graphic=this->CreateGraphics();
penS=gcnew Pen(Color::Red);
penM=gcnew Pen(Color::Blue);
penH=gcnew Pen(Color::Green);
brush=gcnew Drawing::SolidBrush(this->BackColor);
private: System::Drawing::Pen ^penS,^penM,^penH;
System::Drawing::SolidBrush^ brush;
private: System::Int16 rs,rm,rh,centerX,centerY,S,M,H,XS,YS,XM,YM,XH,YH;
System::Double ugolH,ugolM,ugolS;
System::Drawing::Bitmap^ bmp;
System::Drawing::Graphics^ graphic;
private: System::Double gr6;
И ВОТ САМ КОД: (Его пишу в форме.Свойство Paint)
H=DateTime::Now.Hour;
M=DateTime::Now.Minute;
S=DateTime::Now.Second;
//label1->Text=H.ToString()+":"+M.ToString()+":"+S.ToString();
if(H<6) ugolH=5*(3-H)*gr6;
else ugolH=5*(15-H)*gr6;
if(M<30) ugolM=(15-M)*gr6;
else ugolM=(75-M)*gr6;
if(S<30) ugolS=(15-S)*gr6;
else ugolS=(75-S)*gr6;
XS=centerX+rs*Math::Cos(ugolS);
YS=centerY+rs*Math::Sin(ugolS);
XM=centerX+rm*Math::Cos(ugolM);
YM=centerY+rm*Math::Sin(ugolM);
XH=centerX+rs*Math::Cos(ugolH);
YH=centerY+rs*Math::Sin(ugolH);
graphic->Clear(this->BackColor);
graphic->DrawLine(penH,centerX,centerY,XH,YH);
graphic->DrawLine(penM,centerX,centerY,XM,YM);
graphic->DrawLine(penS,centerX,centerY,XS,YS);
Часы идут наоборт!
Люди добрые, скажите в чём ошибка?Рисую часы при помощи GDI+ вроде все в порядке, а часы удут задом-на-перёд(ну в обратную...) , что делать?:eek:
Код:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
namespace clock
{
public class Form1 : System.Windows.Forms.Form
{
#region ZvukFlag
[Flags]
public enum SoundFlags : int
{
SND_SYNC = 0x0000,
SND_ASYNC = 0x0001,
SND_NODEFAULT = 0x0002,
SND_MEMORY = 0x0004,
SND_LOOP = 0x0008,
SND_NOSTOP = 0x0010,
SND_PURGE = 0x40,
SND_NOWAIT = 0x00002000,
SND_ALIAS = 0x00010000,
SND_ALIAS_ID = 0x00110000,
SND_FILENAME = 0x00020000,
SND_RESOURCE = 0x00040004
}
#endregion
#region Zvuk(winmm.dll)
[DllImport("winmm.dll", SetLastError=true)]
static extern bool PlaySound(string pszSound,
System.UIntPtr hmod, uint fdwSound);
public static void Play (string strFileName)
{
PlaySound (strFileName, UIntPtr.Zero, (uint)(SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC));
}
#endregion
#region Elonlar
Graphics graphic;
Pen penH= new Pen(Color.Black,3.0f);
Pen penM= new Pen(Color.Blue,2.0f);
Pen penS= new Pen(Color.MediumSlateBlue);
int H, M, S;
double ugolH,ugolM,ugolS;
double gr6=0.314/3;
int rs=80,centerX=150,centerY=150;
int XS,YS,XM,YM,XH,YH;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
#endregion
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
graphic=this.CreateGraphics();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
UIntPtr ip = UIntPtr.Zero;
bool result = PlaySound(@"C:\Windows\Media\start.wav",ip,0);
this.Refresh();
H=DateTime.Now.Hour-3;
M=DateTime.Now.Minute-15;
S=DateTime.Now.Second-15;
if(H<6) ugolH=5*(3-H)*gr6;
else ugolH=5*(15-H)*gr6;
if(M<30) ugolM=(15-M)*gr6;
else ugolM=(75-M)*gr6;
if(S<30) ugolS=(15-S)*gr6;
else ugolS=(75-S)*gr6;
XS=Convert.ToInt32(centerX+rs*Math.Sin(ugolS));
YS=Convert.ToInt32(centerY+rs*Math.Cos(ugolS));
XM=Convert.ToInt32(centerX+rs*Math.Sin(ugolM));
YM=Convert.ToInt32(centerY+rs*Math.Cos(ugolM));
XH=Convert.ToInt32(centerX+rs*Math.Sin(ugolH));
YH=Convert.ToInt32(centerY+rs*Math.Cos(ugolH));
graphic.DrawLine(penH,centerX,centerY,XH,YH);
graphic.DrawLine(penM,centerX,centerY,XM,YM);
graphic.DrawLine(penS,centerX,centerY,XS,YS);
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
namespace clock
{
public class Form1 : System.Windows.Forms.Form
{
#region ZvukFlag
[Flags]
public enum SoundFlags : int
{
SND_SYNC = 0x0000,
SND_ASYNC = 0x0001,
SND_NODEFAULT = 0x0002,
SND_MEMORY = 0x0004,
SND_LOOP = 0x0008,
SND_NOSTOP = 0x0010,
SND_PURGE = 0x40,
SND_NOWAIT = 0x00002000,
SND_ALIAS = 0x00010000,
SND_ALIAS_ID = 0x00110000,
SND_FILENAME = 0x00020000,
SND_RESOURCE = 0x00040004
}
#endregion
#region Zvuk(winmm.dll)
[DllImport("winmm.dll", SetLastError=true)]
static extern bool PlaySound(string pszSound,
System.UIntPtr hmod, uint fdwSound);
public static void Play (string strFileName)
{
PlaySound (strFileName, UIntPtr.Zero, (uint)(SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC));
}
#endregion
#region Elonlar
Graphics graphic;
Pen penH= new Pen(Color.Black,3.0f);
Pen penM= new Pen(Color.Blue,2.0f);
Pen penS= new Pen(Color.MediumSlateBlue);
int H, M, S;
double ugolH,ugolM,ugolS;
double gr6=0.314/3;
int rs=80,centerX=150,centerY=150;
int XS,YS,XM,YM,XH,YH;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
#endregion
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
graphic=this.CreateGraphics();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
UIntPtr ip = UIntPtr.Zero;
bool result = PlaySound(@"C:\Windows\Media\start.wav",ip,0);
this.Refresh();
H=DateTime.Now.Hour-3;
M=DateTime.Now.Minute-15;
S=DateTime.Now.Second-15;
if(H<6) ugolH=5*(3-H)*gr6;
else ugolH=5*(15-H)*gr6;
if(M<30) ugolM=(15-M)*gr6;
else ugolM=(75-M)*gr6;
if(S<30) ugolS=(15-S)*gr6;
else ugolS=(75-S)*gr6;
XS=Convert.ToInt32(centerX+rs*Math.Sin(ugolS));
YS=Convert.ToInt32(centerY+rs*Math.Cos(ugolS));
XM=Convert.ToInt32(centerX+rs*Math.Sin(ugolM));
YM=Convert.ToInt32(centerY+rs*Math.Cos(ugolM));
XH=Convert.ToInt32(centerX+rs*Math.Sin(ugolH));
YH=Convert.ToInt32(centerY+rs*Math.Cos(ugolH));
graphic.DrawLine(penH,centerX,centerY,XH,YH);
graphic.DrawLine(penM,centerX,centerY,XM,YM);
graphic.DrawLine(penS,centerX,centerY,XS,YS);
}
}
}
Скоро тут будут часы :)