C# 如何在其他应用程序中更改控制器的边界属性
我有一个应用程序A,它监听应用程序B(使用钩子) ListBox 1=我的桌面上的所有应用程序,带有按钮或文本框 正如您所看到的,我已经有了红色矩形,我可以使用两种方法:C# 如何在其他应用程序中更改控制器的边界属性,c#,winforms,C#,Winforms,我有一个应用程序A,它监听应用程序B(使用钩子) ListBox 1=我的桌面上的所有应用程序,带有按钮或文本框 正如您所看到的,我已经有了红色矩形,我可以使用两种方法: var dc = GetWindowDC((LBListControl.SelectedItem as Data).Value); using (Graphics g = Graphics.FromHdc(dc)) { g.DrawRectan
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);
//->第二种方法。
这是我在更改列表框时调用的函数。SelectedIndex
private void LBListControl_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
PaintRedRectangle(LBListControl.SelectedIndex);
}
catch (ArgumentOutOfRangeException)
{
}
}
lRectangle是一个列表,包含我的按钮/文本框的X、Y(宽度/高度由我自己设置)
我听说使用手柄可以更改控制器的BorderStyle/BorderColor。如果这是真的,我没有发现这方面的任何东西,我想知道你是否知道一些事情
否则当我想给别人看的时候,我怎么能压制我的红色矩形呢
顺便说一句:使用g.ReleaseHdc(dc);不工作参数无效(不知道原因)
提前谢谢你感谢雷扎·阿盖伊,我成功了 我创建了一个新表单:
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();
}
}
我把它藏起来了。多亏了雷扎·阿盖伊,我成功了 我创建了一个新表单:
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();
}
}
我把它隐藏起来。看一看,举个例子。我想你不需要改变边框的颜色,在它们周围画一个边框就足够了,事实上是在它们的父图形对象上。当我在我的列表框(我的应用程序上的右列表框是图片)中选择TextBox和Button时,可以改变它们的边框颜色。编辑:没有看到这是一个链接!我要读(一开始没找到)好吧,我的错,我昨天通过:(你在这里也发表了评论:)读了它,但我没有尝试你在这里展示的方法:编辑:是的,我确实想在它们周围画一个边框(这就是为什么我要画一个红色矩形,但我不能将它删除为只有一个矩形。你可能也会发现这篇文章很有用,比如说。我想你不需要改变边框颜色,你只需要在它们周围画一个边框就够了,事实上是在它们的父图形对象上。当我点击时,改变TextBox和Button的边框颜色把它们放在我的列表框(我应用程序中的右边列表框是一张图片)编辑:没有看到它是一个链接!要看它(一开始没有找到)好吧,我很糟糕,我昨天通过:(你在这里也发表了评论:)读了它,但我没有尝试你在这里展示的方法:编辑:是的,我确实想在它们周围画一个边框(这就是为什么我要画一个红色矩形,但我不能删除它,因为它只有一个矩形。你可能会发现这篇文章很有用。)