扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:Adding 来源:YESKY 2007年11月16日
关键字:
... __gc class WinForm: public Form { private: Label *m_pLabelDraw; Splitter *m_pSplitter; Panel *m_pPanel; NumericUpDown *m_pSpinX; NumericUpDown *m_pSpinY; int m_nRectX, m_nRectY; bool m_bChanged; public: WinForm() { m_nRectX = m_nRectY = 10; m_bChanged = true; InitForm(); } void Dispose() { Form::Dispose(); } void InitForm() { Text = S"切分窗口的应用示例"; ClientSize = Drawing::Size(600, 400); m_pLabelDraw = new Label(); m_pSplitter = new Splitter(); m_pPanel = new Panel(); m_pSpinX = new NumericUpDown(); m_pSpinY = new NumericUpDown(); // 构造左边的m_pPanel Label *label1 = new Label(); label1->Location = Drawing::Point(24, 36); label1->Size = Drawing::Size(24, 16); label1->Text = "X = "; m_pSpinX->Location = Drawing::Point(56, 32); m_pSpinX->Size = Drawing::Size(72, 21); m_pSpinX->Minimum = 10; m_pSpinX->Maximum = 1000; m_pSpinX->ValueChanged += new EventHandler(this, &WinForm::DoValueChanged); Label *label2 = new Label(); label2->Location = Drawing::Point(24, 76); label2->Size = Drawing::Size(24, 16); label2->Text = "Y = "; m_pSpinY->Location = Drawing::Point(56, 72); m_pSpinY->Size = Drawing::Size(72, 21); m_pSpinY->Minimum = 10; m_pSpinY->Maximum = 1000; m_pSpinY->ValueChanged += new EventHandler(this, &WinForm::DoValueChanged); GroupBox *groupBox1 = new GroupBox(); groupBox1->Controls->Add(label1); groupBox1->Controls->Add(m_pSpinX); groupBox1->Controls->Add(label2); groupBox1->Controls->Add(m_pSpinY); groupBox1->Location = Drawing::Point(8, 18); groupBox1->Size = Drawing::Size(160, 120); groupBox1->TabStop = false; groupBox1->Text = "坐标设置"; m_pPanel->Controls->Add(groupBox1); m_pPanel->Size = Drawing::Size(176, 144); m_pPanel->Dock = DockStyle::Left; // 再将m_pSplitter、m_pPanel和m_pLabelDraw加入Controls容器中 m_pSplitter->TabStop = false; m_pSplitter->Dock = DockStyle::Left; m_pSplitter->BackColor = Drawing::Color::Green; m_pLabelDraw->BackColor = Drawing::SystemColors::Window; m_pLabelDraw->BorderStyle = BorderStyle::Fixed3D; m_pLabelDraw->Dock = DockStyle::Fill; m_pLabelDraw->MouseDown += new MouseEventHandler(this, &WinForm::DoMouseDown); Controls->Add(m_pSplitter); Controls->Add(m_pLabelDraw); Controls->Add(m_pPanel); Paint += new PaintEventHandler(this, &WinForm::OnPaint); } void DoMouseDown(Object *sender, MouseEventArgs *e) { if (e->Button == MouseButtons::Left){ m_nRectX = e->X; m_nRectY = e->Y; m_bChanged = false; m_pSpinX->Value = m_nRectX; m_pSpinY->Value = m_nRectY; Invalidate(); m_bChanged = true; } } void DoValueChanged(Object *sender, EventArgs *e) { if (m_bChanged) { m_nRectX = (int)m_pSpinX->Value; m_nRectY = (int)m_pSpinY->Value; Invalidate(); } } void OnPaint(Object *sender, PaintEventArgs *e) { m_pLabelDraw->Update(); DrawUserRect(); } void DrawUserRect(void) { Graphics* g = m_pLabelDraw->CreateGraphics(); SolidBrush* backSolid = new SolidBrush(Drawing::Color::White); g->FillRectangle(backSolid,m_pLabelDraw->ClientRectangle); SolidBrush* foreSolid = new SolidBrush(Drawing::Color::Blue); g->FillRectangle(foreSolid,m_nRectX-10,m_nRectY-10,20,20); } }; ... |
图3 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者