我正在开发一个WordSearch拼图程序(也称为WordFind),你必须在其中找到大量字母中的某些单词.我正在使用C#WinForms.
我的问题是当我想点击并按住1个字母(Label),然后拖到其他字母来改变它们ForeColor.我试过谷歌搜索但无济于事.
这是我有的:
foreach (Letter a in game.GetLetters())
{
this.Controls.Add(a);
a.MouseDown += (s, e2) =>
{
isDown = true;
a.ForeColor = Color.Yellow;
};
a.MouseUp += (s, e2) =>
{
isDown = false;
};
a.MouseHover += (s, e2) =>
{
if (isDown)
a.ForeColor = Color.Yellow;
};
}
Run Code Online (Sandbox Code Playgroud)
但是,除非未按住鼠标,否则MouseHover事件永远不会触发.还没有运气换MouseHover用MouseEnter.所以,我保留了MouseDown和MouseUp事件并尝试在表单中使用MouseHover:
private void frmMain_MouseHover(object sender, MouseEventArgs e)
{
if (isDown)
{
foreach (Letter l in game.GetLetters())
if (l.ClientRectangle.Contains(l.PointToClient(Control.MousePosition)))
l.ForeColor = Color.Purple;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用WinForms,在我的窗体上有一个RichTextBox。当我的表单失去焦点但可见时,并且我尝试突出显示/选择文本时,直到表单或文本框本身具有焦点时,它才允许我这样做。
我试过了:
txtInput.MouseDown += (s, e) => { txtInput.Focus(); }
Run Code Online (Sandbox Code Playgroud)
但无济于事,我似乎找不到关于此问题的任何在线信息。
使用记事本之类的其他程序进行测试时,它确实具有所需的行为。
给定主数字和数字子集,想要找到加起来主数字的子集数的所有可能组合.例如:
主要:10
子集:2,3,5,7
结果:3 + 7 = 10,2 + 3 + 5 = 10
**注意:5 + 5 = 10不是有效结果.**
这是我到目前为止的地方:
// Main traversal
for (int a = 0; a < nums.Length; a++)
{
sum = a;
for (int b = a + 1; b < nums.Length; b++)
{
// Thinking this should be the loop that determines
// how many numbers are added together.
// e.g. Sum of 2 numbers, sum of 3 numbers, etc
for (int c …Run Code Online (Sandbox Code Playgroud)