简体   繁体   English

我可以设置富文本框的位置吗?

[英]Can I set position of richtextbox?

I want to set the position of richtextbox by take position of mouse at present.我想通过当前鼠标的位置来设置richtextbox的位置。 I already know how to take mouse position.我已经知道如何获取鼠标位置。 But I don't know how to set the position of richtextbox.但是我不知道如何设置richtextbox的位置。 Of course, position of richtextbox with desktop not with form.当然,richtextbox 与桌面的位置与表单无关。

I tried location, it didn't work.我试过定位,没用。 Expected result:预期结果:

在此处输入图片说明

You can use an additional form without borders with RichTextBox placed on it.您可以使用无边框的附加表单,并在其上放置 RichTextBox。 And change form position by timer.并通过计时器更改表格位置。

Simple example:简单的例子:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Timer timer;
        Form form;
        RichTextBox richTextBox;

        public Form1()
        {
            //InitializeComponent();
            form = new Form
            {
                Size = new Size(50, 20),
                FormBorderStyle = FormBorderStyle.None,
                TopMost = true,
                ShowInTaskbar = false
            };
            richTextBox = new RichTextBox { Parent = form, Dock = DockStyle.Fill };
            timer = new Timer { Interval = 10, Enabled = true };

            timer.Tick += Timer_Tick;
            form.Show();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            form.Location = new Point(MousePosition.X + 10, MousePosition.Y - 20);
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM