| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 830 人关注过本帖
标题:窗体移动显示问题
只看楼主 加入收藏
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:0 
程序代码:
/*

 * Copyright (c) bccn.net ZhouFeng

 */

using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace MoveWindow
{
    public partial class FrmMoveWnd : Form
    {
        //
        // Windows API: MoveWindow
        //
        // hwnd:   Handle to the window.
        // x:      Specifies the new position of the left side of the window.
        // y:      Specifies the new position of the top of the window.
        // width:  Specifies the new width of the window.
        // height: Specifies the new height of the window
        // repaint:Specifies whether the window is to be repainted
        [DllImport("User32.dll")]
        private extern static int MoveWindow(int hwnd, int x, int y, int width, int height, int repaint);

        private bool bIsMoving;
        private Point mouseDownPoint;
        private int xOffset, yOffset;                              

        public FrmMoveWnd()
        {
            InitializeComponent();

            this.bIsMoving = false;
            this.mouseDownPoint = Point.Empty;

            this.Paint += new PaintEventHandler(FrmMoveWnd_Paint);

            // Mouse hanlding
            this.MouseDown += new MouseEventHandler(FrmMoveWnd_MouseDown);
            this.MouseUp += new MouseEventHandler(FrmMoveWnd_MouseUp);
            this.MouseMove += new MouseEventHandler(FrmMoveWnd_MouseMove);
        }

        private void FrmMoveWnd_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.bIsMoving)
            {
                xOffset = e.X - this.mouseDownPoint.X;
                yOffset = e.Y - this.mouseDownPoint.Y;

                MoveWindow((int)this.Handle, this.Left + xOffset, this.Top + yOffset,
                    this.Width, this.Height, 1);
            }
        }

        private void FrmMoveWnd_MouseUp(object sender, MouseEventArgs e)
        {
            this.bIsMoving = false;
        }

        private void FrmMoveWnd_MouseDown(object sender, MouseEventArgs e)
        {
            this.bIsMoving = true;
            this.mouseDownPoint.X = e.X;
            this.mouseDownPoint.Y = e.Y;
        }

        private void FrmMoveWnd_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
           
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;


            Font bigFont = new Font(this.Font.FontFamily, this.Font.Size * 2);

            g.DrawString("Drag window to position.", bigFont, Brushes.DarkBlue, this.ClientRectangle, sf);
        }
    }
}

你好,你看看上面写的是不是你所要的功能。
其实一个API就搞定了。
2011-03-30 12:35
快速回复:窗体移动显示问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027032 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved