实验6 Windows窗体和对话框

做这个实验,挺搞笑的,有的时候拖拉窗口居然不能对齐,汗!代码如下:主要是后面的动作代码。



#pragma once
#include “math.h”
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace Ex_Form {

///

/// ChildForm 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
/// 与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。否则,
/// 设计器将不能与此窗体的关联
/// 本地化资源正确交互。
///

public ref class ChildForm : public System::Windows::Forms::Form
{
public:
ChildForm(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}

protected:
///

/// 清理所有正在使用的资源。
///

~ChildForm()
{
if (components)
{
delete components;
}
}

private:
///

/// 必需的设计器变量。
///

System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
///

/// 设计器支持所需的方法 – 不要
/// 使用代码编辑器修改此方法的内容。
///

void InitializeComponent(void)
{
System::ComponentModel
::ComponentResourceManager^ resources = (gcnew System
::ComponentModel
::ComponentResourceManager(ChildForm::typeid));
this->SuspendLayout();
//
// ChildForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows
::Forms::AutoScaleMode::Font;
this->BackgroundImage = (cli::safe_cast ::Image^ >(resources->GetObject(L”$this.BackgroundImage”)));
this->ClientSize = System::Drawing::Size(192, 173);
this->Name = L”ChildForm”;
this->Opacity = 0.6;
this->Text = L”子窗体”;
this->Load += gcnew System::EventHandler(this,
&ChildForm::ChildForm_Load);
this->MouseUp += gcnew System
::Windows::Forms::MouseEventHandler(this,
&ChildForm::On_MouseUp);
this->MouseDown += gcnew System
::Windows::Forms::MouseEventHandler(this,
&ChildForm::On_MouseDown);
this->MouseMove += gcnew System::Windows
::Forms::MouseEventHandler(this, &ChildForm::On_MouseMove);
this->ResumeLayout(false);

}
#pragma endregion
private:bool m_bIsMouseDown;
private:Point m_ptMouse;
private: System::Void On_MouseDown(System
::Object^ sender, System::Windows
::Forms::MouseEventArgs^ e) {
if(e->Button == MouseButtons){
m_ptMouse=Point(e->X,e->Y);
m_bIsMouseDown = true;
}
else
m_bIsMouseDown = false;
}
private: System::Void On_MouseMove(System
::Object^ sender, System::Windows::Forms
::MouseEventArgs^ e) {
if(!m_bIsMouseDown) return;
//根据鼠标位置偏移量移动窗体
Point pt=this->Location;
this->StartPosition=FormStartPosition::Manual;
abs(pt.X)+=e->X-m_ptMouse.X;
pt.Y+=e->Y-m_ptMouse.Y;
this->Location=pt;
}
private: System::Void On_MouseUp(System::Object^ sender,
System::Windows::Forms::MouseEventArgs^ e) {
m_bIsMouseDown=false;
//调用判断方法CheckIt
if(CheckIt())
MessageBox::Show(”你成功了!”);
else
MessageBox::Show(L”单击【开始】按钮,重新开始!”);
this->Close();
}
public:Point m_ptMainForm;
public:bool CheckIt(){
if(m_ptMainForm==this->Location)
return true;
else
return false;

}
private: System::Void ChildForm_Load(System
::Object^ sender, System::EventArgs^ e) {
}
};
}

版权所有© HzlzH | 本文采用 BY-NC-SA 进行授权
转载需注明 转自: 《实验6 Windows窗体和对话框

随机文章

{ Leave a Reply ? }

  1. a China Mozilla Firefox Windows

    请教下 发这种代码格式的文章用的是什么插件
    编辑器里好像没

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)