简体   繁体   中英

Can I set position of richtextbox?

I want to set the position of richtextbox by take position of mouse at present. I already know how to take mouse position. But I don't know how to set the position of richtextbox. Of course, position of richtextbox with desktop not with form.

I tried location, it didn't work. Expected result:

在此处输入图片说明

You can use an additional form without borders with RichTextBox placed on it. 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);
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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