我正在为Windows Mobile开发一个应用程序(Compact Framework 2.0).它有一个带有PictureBox的WinForms.
我想移动PictureBox的图像,但我不知道该怎么做,所以我选择移动孔PictureBox.
为此,我使用此事件:
private void imagenMapa_MouseMove(object sender, MouseEventArgs e)
{
imagenMapa.Left = e.X;
imagenMapa.Top = e.Y;
this.Refresh();
}
Run Code Online (Sandbox Code Playgroud)
但是当我移动PictureBox时,它会闪烁并移动到每个地方.
我做错了什么?
当用户在富文本框中写入一些单词时,如果该单词与某个特定单词匹配,则该单词的颜色应该自动更改。
当用户单击特定的彩色文本时,它应该引发一个事件。
最近,我将.NET 1.1.4代码迁移到.NET 2.0.0。一切似乎都正常。现在,我尝试通过执行以下操作添加新的模型/表:
dotnet ef update
我得到以下异常:
DbInitializer失败!无法在“ ApplicationUser”上配置密钥,因为它是派生类型。密钥必须在根类型“ IdentityUser”上配置
我有一个扩展IdentityUser的ApplicationUser和扩展IdentityRole的ApplicationRole,这是其他一些教程/ stackoverflow帖子所说的。
我不确定我可能还会错过什么。
在我的ApplicationUser类中,我有:
ICollection<IdentityUserRole<string>>
是否必须是像ApplicationUserRole这样的自定义类型?IdentityUserRole和IdentityRole有什么区别?
编辑:
我认为这可能是因为在我的context.cs文件中,OnModelCreating
我有:
builder.Entity<ApplicationUser>()
.ToTable("AspNetUsers")
.HasKey(x => x.Id);
Run Code Online (Sandbox Code Playgroud)
这Id
是继承自IdentityUser
。
EDIT2:
所以我注释掉了这一行,该错误消失了。转到下一行,这基本上是相同的,但是对于我的ApplicationRole来说,它扩展了IdentityRole。我不太清楚这是什么意思。我是否需要覆盖id属性?
EDIT3:
好的,所以我将builder.Entity中的类型更改为IdentityUser
和IdentityRole
。为什么在我必须使用的startup.cs中ApplicationUser
以及ApplicationRole
调用时可以解决此问题services.AddIdentity<ApplicationUser, ApplicationRole>
使用user32.dll
C#,我编写了下面看到的方法。使用窗口的处理手柄,它将在指定{x,y}
位置设置窗口位置。
但是,在多监视器环境中,下面的代码仅将窗口位置设置为主监视器。我也希望能够选择哪个显示器。
有人可以解释一下如何使用SetWindowPos
或结合其他user32.dll
功能来实现吗?
[DllImport("user32.dll", SetLastError = true)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
private const int SWP_NOSIZE = 0x0001;
private const int SWP_NOZORDER = 0x0004;
private const int SWP_SHOWWINDOW = 0x0040;
public static void SetWindowPosition(Process p, int x, int y)
{
IntPtr handle = p.MainWindowHandle;
if (handle != IntPtr.Zero)
{
SetWindowPos(handle, IntPtr.Zero, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW); …
Run Code Online (Sandbox Code Playgroud) 我的程序必须在RichTextBox中找到特定的单词并更改它们的颜色(简单的语法高亮显示).我Regex
用来找到这些词.
我能够找到所有这些,但如果我的文字包含2个或更多相同的单词,我只能改变第一个的颜色,其他的不受影响.
Dim words As String = "(in|handles|object|sub|private|dim|as|then|if|regex)"
Dim rex As New Regex(words)
Dim mc As MatchCollection = rex.Matches(RichTextBox1.Text.ToLower)
Dim lower_case_text As String = RichTextBox1.Text.ToLower
For Each m As Match In mc
For Each c As Capture In m.Captures
MsgBox(c.Value)
Dim index As Integer = lower_case_text.IndexOf(c.Value)
Dim lenght As Integer = c.Value.Length
RichTextBox1.Select(index, lenght)
RichTextBox1.SelectionColor = Color.Blue
Next
Next
Run Code Online (Sandbox Code Playgroud)
我的代码需要从单击按钮运行.我认为我的问题在for each
循环中,但我不确定.
我已经有了它的几个版本,但都没有工作.
System.Diagnostics.DebuggerStepThrough
在Visual Studio Debugger中工作时,我一直在使用该属性来跳过代码.
但是,有时我希望它也跳过从我应用DebuggerStepThrough
属性的方法中调用的任何方法.
有没有办法做到这一点?
我不希望这会影响我应用此属性的所有方法,但有时候我不希望任何代码被调用/用于打开我已应用的方法中调用的所有方法的调试器这个属性.
static void main(string[] args)
{
Method1();
}
[DebuggerStepThrough()]
private static void Method1()
{
Method2(); 'The Debugger is stopping in Method2 when I am manually stepping through the code
}
private static void Method2()
{
'... Code I don't care about however debugger is stopping here.
}
Run Code Online (Sandbox Code Playgroud)
所以上面的代码示例是我遇到的一个例子.
有没有办法让我告诉Visual Studio还要跨越从内部调用的方法Method1()
?
目前,当我在Visual Studio中手动单步执行代码时,我发现[DebuggerStepThrough()]
即使从应用了属性的方法中调用它们,我也必须将属性添加到所有调用的方法中.在此示例中,调试器正在内部停止Method2()
.
我希望有一种方法可以让我不必将这个属性应用于从Parent方法调用的所有方法.
也许这只是我想念的东西.
如何使用PrintDocument
可滚动面板`?
这是我的一些代码:
MemoryImage = new Bitmap(pnl.Width, pnl.Height);
Rectangle rect = new Rectangle(0, 0, pnl.Width, pnl.Height);
pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pnl.Width,
pnl.Height));
Rectangle pagearea = e.PageBounds;
e.Graphics.DrawImage(MemoryImage, (pagearea.Width / 2) -
(pannel.Width / 2), pannel.Location.Y);
Run Code Online (Sandbox Code Playgroud) 我们如何从一个表单 (settings.form) 更改所有其他表单的背景颜色?我想开发我的毕业项目。它是一个社交媒体桌面管理项目。我想用一个切换器将所有表单更改为暗模式。我怎样才能做到这一点?这是我的 settings.cs
public void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
panel1.BackColor= Color.FromArgb(34, 36, 49);
form1.BackColor = Color.FromArgb(34, 36, 49);
form2.BackColor = Color.FromArgb(34, 36, 49);
this.BackColor = Color.FromArgb(34, 36, 49);
this.label1.BackColor = Color.White;
this.label1.ForeColor = Color.FromArgb(34, 36, 49);
}
else
{
this.BackColor = Color.White;
this.label1.BackColor = Color.FromArgb(34, 36, 49);
this.label1.ForeColor = Color.White;
}
form1.Show();
form1.Refresh();
form2.Show();
form2.Refresh();
Run Code Online (Sandbox Code Playgroud)
当我切换时,所有背景颜色都在变化。但所有表格都同时打开。
我想导航到 URL,而不是打开一个单独的实例。
无论我做什么,它仍然会打开 WebView2 的另一个实例。
private void CoreWebView2_NewWindowRequested(object sender,
CoreWebView2NewWindowRequestedEventArgs e)
{
//e.NewWindow = webView21.CoreWebView2;
e.NewWindow = (CoreWebView2)sender;
//e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
这是原始帖子,我需要做什么才能处理新窗口请求?
我正在使用 C# .NET 5.0 列出文件夹中的 PDF 文件,当双击某个项目时,它会使用 Windows 默认 PDF 查看器打开选定的 PDF。
我已经搜索了如何执行此操作,但解决方案代码引发了异常。
System.Diagnostics.Process.Start(@"C:\path\to\pdf\file.pdf");
Run Code Online (Sandbox Code Playgroud)
错误:
System.ComponentModel.Win32Exception: 'The specified executable is not a valid application for this OS platform.'
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?