c# 鼠标管轮
2016-07-07 13:05:00 weixin_34290096 阅读数 1

对FlowLayoutPanel添加鼠标滚轮事件

在mainform中添加事件

his.flowLayoutPanel1.MouseWheel +=
                new System.Windows.Forms.MouseEventHandler(this.flowLayoutPanel1_MouseWheel);

添加滚轮事件函数:

private void flowLayoutPanel1_MouseWheel(object sender, MouseEventArgs e) { if (!(flowLayoutPanel1.VerticalScroll.Visible == false || (flowLayoutPanel1.VerticalScroll.Value == 0 && e.Delta > 0) || (flowLayoutPanel1.VerticalScroll.Value == lastRightPanelVerticalScrollValue && e.Delta < 0))) { flowLayoutPanel1.VerticalScroll.Value += 10; lastRightPanelVerticalScrollValue = flowLayoutPanel1.VerticalScroll.Value; flowLayoutPanel1.Refresh(); flowLayoutPanel1.Invalidate(); flowLayoutPanel1.Update(); } }

 

除此之外还要说的一点是,触发鼠标的滚动事件后,处理事件的函数参数 MouseEventArgs e 中有个Delta属性,默认情况下向上滚动e.Delta=120,向下滚动e.Delta=-120。以上的程序还不是特别完美,因为当Panel控件较大而没有显示滚动条时,或滚动条已在最上方而滚轮又是向上滚动,或滚动条已在最下方而滚轮又是向下滚动时,同样会执行Panel.Refresh();Panel.Invalidate();Panel.Update();等窗体重绘代码,占用较多资源。因此可以在执行这些代码前先对Panel的当前状况做判断。

int lastRightPanelVerticalScrollValue = -1;//为鼠标滚动事件提供一个静态变量,用来存储上次滚动后的VerticalScroll.Value

添加FlowLayoutPanel的鼠标进入事件和鼠标点击事件

private void flowLayoutPanel1_MouseEnter(object sender, EventArgs e) { flowLayoutPanel1.Focus(); } private void flowLayoutPanel1_MouseClick(object sender, MouseEventArgs e) { flowLayoutPanel1.Focus(); }

 

转载于:https://my.oschina.net/mzy666888/blog/707689

2016-02-22 10:05:11 mzy666888 阅读数 195
对FlowLayoutPanel添加鼠标滚轮事件

在mainform中添加事件

his.flowLayoutPanel1.MouseWheel +=
                new System.Windows.Forms.MouseEventHandler(this.flowLayoutPanel1_MouseWheel);

添加滚轮事件函数:

private void flowLayoutPanel1_MouseWheel(object sender, MouseEventArgs e)
{
     if (!(flowLayoutPanel1.VerticalScroll.Visible == false || (flowLayoutPanel1.VerticalScroll.Value == 0 && e.Delta > 0) || (flowLayoutPanel1.VerticalScroll.Value == lastRightPanelVerticalScrollValue && e.Delta < 0)))
     {
          flowLayoutPanel1.VerticalScroll.Value += 10;
          lastRightPanelVerticalScrollValue = flowLayoutPanel1.VerticalScroll.Value;
          flowLayoutPanel1.Refresh();
          flowLayoutPanel1.Invalidate();
          flowLayoutPanel1.Update();
     }
}

 

除此之外还要说的一点是,触发鼠标的滚动事件后,处理事件的函数参数 MouseEventArgs e 中有个Delta属性,默认情况下向上滚动e.Delta=120,向下滚动e.Delta=-120。以上的程序还不是特别完美,因为当Panel控件较大而没有显示滚动条时,或滚动条已在最上方而滚轮又是向上滚动,或滚动条已在最下方而滚轮又是向下滚动时,同样会执行Panel.Refresh();Panel.Invalidate();Panel.Update();等窗体重绘代码,占用较多资源。因此可以在执行这些代码前先对Panel的当前状况做判断。

int lastRightPanelVerticalScrollValue = -1;//为鼠标滚动事件提供一个静态变量,用来存储上次滚动后的VerticalScroll.Value

添加FlowLayoutPanel的鼠标进入事件和鼠标点击事件

private void flowLayoutPanel1_MouseEnter(object sender, EventArgs e)
{
      flowLayoutPanel1.Focus();
}
private void flowLayoutPanel1_MouseClick(object sender, MouseEventArgs e)
{
      flowLayoutPanel1.Focus();
}

 

C# 库管
2016-11-16 06:56:33 qq_36074073 阅读数 167

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace ConsoleApplication1 {     class Class1     {                Class2[] a = new Class2[3];         public void xianshi()         {             yi();                       Console.WriteLine("1:根据货品名称获取货品位置 2:取得客户满意度最高的货品 3:退出");             Console.WriteLine("请选择");             String i=Console.ReadLine();             switch(i){                 case "1":                                        y();                     break;                     case "2":                     er();                                        break;                     case "3":                     break;             }                   }         public void yi() {             a[0]=new Class2();             a[0].Name="杯子";             a[0].Redu = 97;             a[0].Jiage = 18.5;             a[0].Weizhi = "第一排";             a[1] = new Class2();             a[1].Name = "花瓶";             a[1].Redu = 99;             a[1].Jiage = 14;             a[1].Weizhi = "第二排";             a[2] = new Class2();             a[2].Name = "热水器";             a[2].Redu = 88;             a[2].Jiage = 50.8;             a[2].Weizhi = "第三排";                 }         public void y() {                         Console.WriteLine("输入商品名称");

            String ming = Console.ReadLine();             foreach (Class2  i in a)             {                 if (i.Name.Equals(ming))                 {                                         Console.WriteLine(i.Weizhi);                     break;                 }                 else {                     Console.WriteLine("输入的名称不存在");                     break;                                     }             }                 }         public void er() {             Class2 er = new Class2();             er = panduan();             String name = String.Format("客户满意度最高的商品{0},摆放在{1},价格为{2},满意度{3}",er.Name,er.Weizhi,er.Jiage,er.Redu);             Console.WriteLine(name);         }         public Class2 panduan() {             Class2 er = new Class2();               er.Redu = 0;             foreach (Class2 item in a)             {                 if(item.Redu>er.Redu){                     item.Jiage = er.Jiage;                     item.Name = er.Name;                     item.Weizhi = er.Weizhi;                     item.Redu = er.Redu;                                         }             }             return er;         }

    } }

Class2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace kucunguanli
{
    class Class2
    {
        private String name;

        public String Name
        {
            get { return name; }
            set { name = value; }
        }
        private String weizhi;

        public String Weizhi
        {
            get { return weizhi; }
            set { weizhi = value; }
        }
        private int redu;

        public int Redu
        {
            get { return redu; }
            set { redu = value; }
        }
        private double jiage;

        public double Jiage
        {
            get { return jiage; }
            set { jiage = value; }
        }
    }
}
Main方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace kucunguanli
{
    class Program
    {
        static void Main(string[] args)
        {
            Class1 a = new Class1();
            a.xianshi();
           
          
            Console.ReadLine();
        }
    }
}

2018-10-04 11:25:37 qq_38244423 阅读数 45

此问题曾困扰了几天的时间,通过网上搜索相关文章,终于解决!庆幸不已!我在想C#也算是高级语言,为什么会出现这个问题,令人费解!
问题描述:在子窗体有边框的情况下,还要可以使用鼠标选取文本!
解决方案:父窗体、子窗体都是普通窗体(非MDI窗体),在调用子窗体时,使用下列代码:
zxsj = new zxsj_edit();
zxsj.TopLevel =true;
zxsj.Dock = DockStyle.None;
//zxsj.FormBorderStyle = FormBorderStyle.None;
SetParent(zxsj.Handle.ToInt32(), this.Handle.ToInt32());
//zxsj.Parent = this;
zxsj.StartPosition = FormStartPosition.CenterParent;
zxsj.BringToFront();
zxsj.Size = new Size(zxsj.Width < this.Size.Width ? zxsj.Width : this.Width, zxsj.Height < this.Size.Height ? zxsj.Height : this.Height);
zxsj.Location = new Point((this.Width - zxsj.Width) / 2, (this.Height - zxsj.Height) / 2 - 20);
zxsj.FormClosed += main_form_state_recover_zxsj1;
zxsj.TopMost = true;
zxsj.Show();

///以下为SetParent函数的引用方法:

[DllImport(“user32”)]
public static extern int SetParent(int hWndChild, int hWndNewParent);

2011-09-25 13:11:06 kingzhexian 阅读数 301
using System;
using System.Drawing;
using System.Windows.Forms;

namespace ClipScreen
{
    public partial class FormScreen : Form
    {
        private NotifyIcon notifyInfo;

        public FormScreen()
        {
            #region
            InitializeComponent();
            this.TopMost = true; // 前端显示。
            this.ShowInTaskbar = false;    // 在 Windows 任务栏中隐藏窗体。
            this.DoubleBuffered = true;   // 双缓冲绘制图形。
            this.FormBorderStyle = FormBorderStyle.None; // 窗体无边框。
            this.BackgroundImageLayout = ImageLayout.None; // 图像沿控件的矩形工作区顶部左对齐。
            this.DesktopBounds = Screen.GetWorkingArea(this); // 获取桌面区域。
            this.TransparencyKey = this.BackColor; // 窗体透明化。
            this.BackgroundImage = new Bitmap(this.Width, this.Height);
            using (Graphics g = Graphics.FromImage(this.BackgroundImage))
            {
                g.CopyFromScreen(Point.Empty, Point.Empty, this.Size);
            }
            notifyInfo = new NotifyIcon();
            notifyInfo.Visible = true;
            notifyInfo.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            notifyInfo.Text = AppDomain.CurrentDomain.FriendlyName;
            notifyInfo.BalloonTipClosed += new EventHandler(notifyInfo_BalloonTipClosed);
            notifyInfo.Click += new EventHandler(notifyInfo_Click);
            #endregion
        }

        #region OnMouseMove
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.Button == MouseButtons.Left)
                using (Graphics g = this.CreateGraphics())
                {
                    g.FillEllipse(Brushes.Cyan, e.X, e.Y, 10, 10);
                }
        }
        #endregion

        #region OnMouseUp
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (e.Button == MouseButtons.Right)
                this.Refresh();
        }
        #endregion

        #region NotifyIcon
        private void notifyInfo_Click(object sender, EventArgs e)
        {
            notifyInfo.ShowBalloonTip(10, notifyInfo.Text, "    在系统托盘中运行", ToolTipIcon.Info);
        }

        private void notifyInfo_BalloonTipClosed(object sender, EventArgs e)
        {
            notifyInfo.Visible = false;
            Application.Exit();
        }
        #endregion
    }
}

C# 鼠标操作

阅读数 348

cursor.current=currents.sizeWE;

博文 来自: vivianshen0406

C#的鼠标控制代码

阅读数 14

原文:http://free56.cn/post/10.htmlC#的鼠标控制代码//usingSystem.Runtime.InteropServices;        [Flags]       enumMouseEventFlag:uint       {           Move=0x0001,           LeftDown=...

博文 来自: weixin_34348111

C#的鼠标控制代码

阅读数 857

 //usingSystem.Runtime.InteropServices;        [Flags]       enumMouseEventFlag:uint       {           Move=0x0001,           LeftDown=0x0002,           LeftUp=0x0004,          

博文 来自: cnming

C#鼠标跟踪

阅读数 398

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.W

博文 来自: zc2007071032

C# 的鼠标状态

阅读数 636

this.Cursor=Cursors.WaitCursor;//等待this.Cursor=Cursors.Default;//正常状态

博文 来自: anton311
没有更多推荐了,返回首页