I'm trying to write a simple text editor like DarkRoom with just a RichTextBox (or alternatively a TextBox) in it. My problem is that I can't use the mouse wheel for scrolling unless I have a vertical scrollbar. Is there any way to hide this scrollbar and still be able to scroll with the mouse wheel?
So far I have several ideas how this could be done, but no idea how to implement them.
re-create the scrolling code using a MouseWheel event
change the visual style of the scrollbar to hide it or make it less visible
write my own TextBox widget
overlap the scrollbars with something else to hide them
P.S.: Using any win32 stuff is not an option.
Yes, you will have to capture the .MouseWheel and .MouseMove events. See this post.
Ok, do something like following:
Add a line in form load event.
private void Form1_Load(object sender, EventArgs e)
{
this.richTextBox1.MouseWheel += new MouseEventHandler(richTextBox1_MouseWheel);
}
Add following in mouse wheel event.
void richTextBox1_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta > 0)
{
//Handle mouse move upwards
if (richTextBox1.SelectionStart > 10)
{
richTextBox1.SelectionStart -= 10;
richTextBox1.ScrollToCaret();
}
}
else
{
//Mouse move downwards.
richTextBox1.SelectionStart += 10;
richTextBox1.ScrollToCaret();
}
}
Let me know in either cases, if you would want the running sample of the same; or if you are not liking the solution (0:
Related
I am trying to write a program to manage tasks from my team. For this I use drag&drop capable custom UserControls. I try the following: When the UserControl is dragged over a slot, the control should then snapped into the slot. The problem seems to be that the slot does not get the events like "MouseEnter" or "DragEnter". Does anyone know a workaround, or is it possible to pass events down?
I think I just need a little push in the right direction.
Edit:
Main functionality:
The user control, let's call it task, should be docked into a slot when released over it.
A slot consists of properties and a panel. The task should appear in the panel.
Bonus:
A task, should dock into the different slots while dragging. So that it is always visible where the 'task' is placed when it is released.
I hope this shows what I am trying to do.
Edit 2
To clarification: I use the "MouseDown", "MouseUp" and "MouseMove" for the drag an drop.
Here you can see my Example the blueish panel is my task. The white the slot it should snap to.
On the second picture I drag the Task over the Slot panel. The mouse is not visable here but it's right beside the "K" of task.
i have added for testing the following code. Which should color the panel inside the slot in a color if an event is raised. But the color stays white.
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
this.panel1.BackColor = Color.Black;
}
private void panel1_MouseEnter(object sender, EventArgs e)
{
this.panel1.BackColor = Color.Green;
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
this.panel1.BackColor = Color.Yellow;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
this.panel1.BackColor = Color.Violet;
}
Why I don't get events on the Slotpanel?
I hope that this helps to understand my problem.
Like the RichTextBox, I want to be able to handle events for when the vertical scrollbar has been adjusted (through slider dragging, the mouse wheel or otherwise), and for when the caret / text cursor has been moved. However, these events appear to be missing from Scintilla. How can I achieve the same result?
Both of those are available under the UpdateUI event via the UpdateChange structure. Example:
private void scintilla1_UpdateUI(object sender, ScintillaNET.UpdateUIEventArgs e)
{
if (e.Change == ScintillaNET.UpdateChange.VScroll)
{
...
}
}
I have placed my Picture Box in the center of my Form, but I don't know how to make it move with the use of buttons.
I need to use a Class Library in the process, so my guess is that using if structure is out of the question?
Make a picture box and a button
This code for the click of a button should move your box 10 left of its current position:
private void button1_Click(object sender, EventArgs e)
{
this.pictureBox1.Left = this.pictureBox1.Left - 10;
}
You can also use this.pictureBox1.Top to move it vertically.
Make it an addition to .Left or .Top to make it go the opposite direction.
That should give you a nice start!
I am new to c# Windows Form Application Development.
I created a form with a panel in which the user can draw image on it. How do I check if the image is clicked?
In designer mode, right-click on the panel, go to Properties.
In the Properties window, choose EVENTS (Lightning icon).
Double click on Click, then this code will be generated:
private void panel1_Click(object sender, EventArgs e)
{
//--what to do when user clicks on panel--
MessageBox.Show("Clicked");
}
Just double-click on the form's image-panel (or whatever object you wish to detect click events on) and Visual Studio will automatically generate a OnClick() event. Needless to say, I'm talking about the forms designer, not the actual form you will see when testing your code.
Alternatively, you can set which events you want to implement through the object's properties. That way you can also implement OnKeyDown() or OnFocus() or any other kind of events.
Edit: If the image doesn't cover the entire panel, you'll have to check if the mouse position is within the image's dimension. Assuming the image is drawn at position (imgOriginX, imgOriginY) and has the size (imgWidth, imgHeight):
// Fires, when user clicks on panel
private void panel_Click(object sender, EventArgs e)
{
// Cast to MouseEventArgs
MouseEventArgs mouse = (MouseEventArgs)e;
// If mouse is within image
if (mouse.X >= imgOriginX && mouse.Y >= imgOriginY && mouse.X < imgOriginX + imgWidth && mouse.Y < imgOriginY + imgHeight)
{
// do something here
}
}
I have WebBrowser class and image loaded in it. After mouse click on the browser, I need to get mouse position - what is the best way to do it?
this is actually pretty simple if your just looking for the screen coordinates.
// this probably should be in your form initialization
this.MouseClick += new MouseEventHandler(MouseClickEvent);
void MouseClickEvent(object sender, MouseEventArgs e)
{
// do whatever you need with e.Location
}
if your strictly looking for the point in the browser, you need to consider the functions
browser.PointToClient();
browser.PointToScreen();