【问题标题】:How to change border property of controller in other application如何在其他应用程序中更改控制器的边框属性
【发布时间】:2017-11-10 09:15:24
【问题描述】:

我有一个应用程序 A 监听应用程序 B(使用 Hook)

1

ListBox 1 = 我桌面上所有带有按钮或文本框的应用程序

如你所见,我已经有了红色矩形,我可以使用两种方法:

var dc = GetWindowDC((LBListControl.SelectedItem as Data).Value);
            using (Graphics g = Graphics.FromHdc(dc))
            {
                g.DrawRectangle(Pens.Red, 0,0,50,20);
                g.Dispose();
                g.ReleaseHdc(dc);
            }
            // paintedRectangle = lRectangle[i];
            //ControlPaint.DrawReversibleFrame(paintedRectangle, SystemColors.Highlight, FrameStyle.Dashed);

// -> 第二种方法。 这是我在更改 ListBox.SelectedIndex 时调用的函数

private void LBListControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                PaintRedRectangle(LBListControl.SelectedIndex);
            }
            catch (ArgumentOutOfRangeException)
            {

            }
        }

lRectangle 是一个列表,其中包含我的按钮/文本框的 X、Y(宽度/高度由我自己设置)。

我听说使用手柄可以更改控制器的 BorderStyle / BorderColor。如果是真的,我没有找到任何相关信息,我想知道你是否知道。

否则,当我想向其他人展示时,我怎么能抑制我的 RedRectangle 呢?

顺便说一句:使用 g.ReleaseHdc(dc);无效参数无效(不知道为什么)

提前谢谢你

【问题讨论】:

标签: c# winforms


【解决方案1】:

感谢 Reza Aghaei 我成功了!

我创建了一个新表单:

public partial class InvisibleFrame : Form
    {
        public InvisibleFrame()
        {
            InitializeComponent();
            BackColor = Color.Lime;
            TransparencyKey = Color.Lime;
            FormBorderStyle = FormBorderStyle.None;
            ShowInTaskbar = false;
        }
    }

我在这里打电话:

private void PaintRedRectangle(int i)
    {
        try
        {
            ci.Location = new Point(lRectangle[i].X, lRectangle[i].Y);
            ci.Size = new Size(10, 10);
            ci.BackColor = Color.Red;
            ci.BringToFront();
            ci.Show();
        }
        catch(ObjectDisposedException)
        {
            ci = new InvisibleFrame();
            PaintRedRectangle(i);
        }
    }

然后我选择按钮和我想挂钩的文本框:

private void BTHookTB_Click(object sender, EventArgs e)
{
    if (sender != null)
    {
        ControlHook TextBoxHook = new ControlHook
        {
            Text = LBListControl.SelectedItem.ToString(),
            Position = lRectangle[LBListControl.SelectedIndex],
        };
        lControlHook.Add(TextBoxHook);
        LabelTBHook.Text = "TextBox : " + lControlHook[1].Text;
        BTHookTB.Enabled = false;
        BTReset.Enabled = true;
        BTHook.Enabled = true;
        LBListControl.Enabled = false;
        ci.Hide();
    }
}

我把它藏起来了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多