winforms

Change space between Image and Text in ContextMenuStrip

ⅰ亾dé卋堺 提交于 2021-02-10 12:43:27
问题 In my application, I have a ContextMenuStrip with two items. Each item has an image and a text. There's a default gap between the Image section of the Menu Items and their text, as shown in the image below (the gap is indicated by red arrows). I want to reduce the horizontal gap by moving the text towards the left, so that the gap is reduced to a maximum of 1 pixel. Is it possible? If yes how can I? 回答1: A sample setup that shows how to handle a generic ToolStripProfessionalRenderer and a

How do I override Ctrl+Shift+0 (zero) for WinForms RichTextBox?

一曲冷凌霜 提交于 2021-02-10 12:13:45
问题 For my subclassed RichTextBox class, I can capture, suppress the default behaviour of and re-purpose Ctrl+Shift+#, as long as # is between 1 and 9. For Ctrl+Shift+0, I can't. I have experimented with ProcessCmdKey in the form class and onKeyDown and PreProcessMessage in the control class. Here is sample code meant for the control class that should suppress Ctrl+Shift+0 but does not: public override bool PreProcessMessage(ref Message msg) { bool cancel = false; int vKeyCode = (int)msg.WParam;

How do I override Ctrl+Shift+0 (zero) for WinForms RichTextBox?

一世执手 提交于 2021-02-10 12:13:12
问题 For my subclassed RichTextBox class, I can capture, suppress the default behaviour of and re-purpose Ctrl+Shift+#, as long as # is between 1 and 9. For Ctrl+Shift+0, I can't. I have experimented with ProcessCmdKey in the form class and onKeyDown and PreProcessMessage in the control class. Here is sample code meant for the control class that should suppress Ctrl+Shift+0 but does not: public override bool PreProcessMessage(ref Message msg) { bool cancel = false; int vKeyCode = (int)msg.WParam;

How do I override Ctrl+Shift+0 (zero) for WinForms RichTextBox?

穿精又带淫゛_ 提交于 2021-02-10 12:13:08
问题 For my subclassed RichTextBox class, I can capture, suppress the default behaviour of and re-purpose Ctrl+Shift+#, as long as # is between 1 and 9. For Ctrl+Shift+0, I can't. I have experimented with ProcessCmdKey in the form class and onKeyDown and PreProcessMessage in the control class. Here is sample code meant for the control class that should suppress Ctrl+Shift+0 but does not: public override bool PreProcessMessage(ref Message msg) { bool cancel = false; int vKeyCode = (int)msg.WParam;

Combobox DataBinding Bug - Won't write value if programmatically losing focus

守給你的承諾、 提交于 2021-02-10 12:03:46
问题 I have a blank form, to which I've added a default ComboBox , TextBox (just for receiving focus), and Label . The combobox has a databinding set up to a private property on the form. Setup: Private Sub FormLoad(sender As System.Object, e As System.EventArgs) _ Handles MyBase.Load Dim data = {New With {.Display = "", .Value = ""}, New With {.Display = "A", .Value = "A"}, New With {.Display = "B", .Value = "B"}, New With {.Display = "C", .Value = "C"}} ComboBox1.DataSource = data ComboBox1

How to organize a HIERARCHY of non-UI threads and get status and progress back for UI consumption

廉价感情. 提交于 2021-02-10 07:26:20
问题 Figure 1 - Working Demo I'm running a winforms application and I have implemented a status / progress TreeView. It can display the status (by icon) and progress of a (possibly hierarchical) set of tasks to accomplish. My question is not about how to implement the TreeView control itself. I've got that part covered. The TreeView is merely the way the background work is going to status / progress itself to the user. I have a set of methods that I want to run on not the main UI thread. They need

WinForm Bottom Margin Property Doesn't Do Anything

时光总嘲笑我的痴心妄想 提交于 2021-02-10 06:20:30
问题 I am new to WinForms, and I am very used to styling in CSS, so maybe I am not looking at WinForm's Bottom Margin property correctly, but, no matter what element I set an arbitrarily large bottom-margin number to, it seems to have no effect, at all. What I want is to extend the design of the form to below the initial viewable window (vertical-scroll bar shows up just fine), and set a bottom-margin to these elements so that the very bottom of the element isn't flush with the very bottom of the

Calculating Exact Pixels for a line

自闭症网瘾萝莉.ら 提交于 2021-02-10 06:11:35
问题 Say i want to try to make a straight line albeit with any angle public class Line : Control { public Point start { get; set; } public Point end { get; set; } public Pen pen = new Pen(Color.Red); protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawLine(pen, start, end); base.OnPaint(e); } } This line has been made on a custom control. Now how can i calculate the exact pixels on which the line has been made so i can implement a hit test with MouseMove . 回答1: There are Win32 calls

How to use a button click event in c# to activate run a desktop shortcut to open a program

删除回忆录丶 提交于 2021-02-10 05:42:14
问题 I have many shortcuts on the desktop and some work on the newer windows store apps that reside in the windowsapps folder, that cannot be run by clicking the exe file. so I want to use a button in my c#.net winforms app so when I click on it, it is the same as if I double clicked the icon on the desktop. I do not know enough about shell execute to know if that can do it. Any help would be greatly appreciated 回答1: Have you tried System.Diagnostics.Process.Start(fullPath) in your button click

Field is never assigned to and will always have its default value 0

夙愿已清 提交于 2021-02-10 05:19:07
问题 I get the following error in my code and I'm not sure why: Warning - 'SummaryForm.m_difficulty' is never assigned to, and will always have its default value 0 Code public partial class SummaryForm : Form { // Declares variables with the values pulled from the 'MainForm' int iCorrectACount = MainForm.iCorrectACount; int iCurrentQIndex = MainForm.iCurrentQIndex; private Difficulty m_difficulty; public SummaryForm() { InitializeComponent(); double modifier = 1.0; if (m_difficulty == Difficulty