473,770 Members | 5,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to: Move a button like a scrollbar slider?

Hi,
I've made a custom scrollbar which consists of three buttons and a panel. My problem is: How do I move it like a scrollbar slider? I've tried DoDragDrop, but it does not appear to be the same, all though I can move the button. I have also used the mouseMove event, so I can move the button, but it's completely out of control. Still I feel it's the right way to go. This is what I've written:

private void btnSecond_Mouse Move(object sender, System.Windows. Forms.MouseEven tArgs e)
{
if (MouseButtons.L eft == e.Button)
{
btnSecond.Top = e.Y;
PositionToValue (btnSecond.Top) ;
}
}

private int PositionToValue (int pos)
{
return (_maxValue / (panelArea.Heig ht-btnSecond.Heigh t)) * pos;
}

Anyone who can help me out?

Thanks, gmtongar
Nov 16 '05 #1
1 8501
gmtongar wrote:
Hi,
I've made a custom scrollbar which consists of three buttons and a panel. My problem is: How do I move it like a scrollbar slider? I've tried DoDragDrop, but it does not appear to be the same, all though I can move the button. I have also used the mouseMove event, so I can move the button, but it's completely out of control. Still I feel it's the right way to go. This is what I've written:

private void btnSecond_Mouse Move(object sender, System.Windows. Forms.MouseEven tArgs e)
{
if (MouseButtons.L eft == e.Button)
{
btnSecond.Top = e.Y;
PositionToValue (btnSecond.Top) ;
}
}

private int PositionToValue (int pos)
{
return (_maxValue / (panelArea.Heig ht-btnSecond.Heigh t)) * pos;
}

Anyone who can help me out?

Thanks, gmtongar


Here is what I did to "drag drop" my form that had no title bar.
//First create three global variables
int curDifX,curDifY ;
bool drag = false;

//now to the event handlers
private void button_MouseDow n(..)
{
//not sure about button.Left here but it should be the position of your
button
curDifX = Cursor.Position .X-button.Left;
curDifY = Cursor.Position .Y-button.Top;
drag = true;
}

private void button_MouseMov e(...)
{
if (drag)
{
button.Left = Cursor.Position .X-curDifX;
button.Top = Cursor.Position .Y-curDifY;
}
}

//and finally
private void button_MouseUp( ...)
{
drag = false;
}

This will make it look like you are able to click hold, move and drop a
button. In your case, since it is a slider, you could only monitor the X
value of the mouse, which would only allow you to move the control
horizontally.

Hope I understood your question correctly.

Nick Z.
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9285
by: Richard van Wegen | last post by:
Dear All I want to use the horizontal scrollbar control, but I can't figure out how to change the width of the slider, i.e. the bit that you drag left & right. With other controls (eg Textbox), the inbuilt scrollbar changes its slider width depending on how much text is in the box. But the slider width of the horizontal scrollbar control always seems to be the same size. Can anyone tell me how to do this?
1
5560
by: yihan | last post by:
Hi, I would like to make a pageUp and pageDown button to go up or down in the text ( it is like PgUp/PgDown on the keyboard). But it works on the IE but not on netscape 7.1. Could somebody tell me the problem? Thanks. The code as below: <HTML> <style type="text/css"> <!-- body
5
20233
by: Z | last post by:
Hi, I have problem with auto-scrolling frames in IE (6.0 on Xp, but same happens with IE 5.5 on Win2k): If I set scrolling="auto" to frame, IE reserves space where vertical scrollbar normally goes and doesn't render contents there when scrollbar is hidden. Here is frameset with left and right frames:
6
7557
by: Skip Hollowell | last post by:
I am working on a menu bar for a site, and am using buttons in the bar (because the customer wants to use accessKeys for each selection, apparently it is too much work to click on them with a mouse, but I digress) It seems that the longer the text is in a button, the more padding there is around that text in the button, thus making the button itself much to wide, and wasting too much space on the page. I have tried width:auto in the...
0
1675
by: Frnak McKenney | last post by:
I have a (small) multi-table database application which allows edits, print reports, and has two scrolling screen displays which show information merged from multiple tables. I'm having trouble with one of the scrolling displays which is implemented as a DataGrid with several custom DataGridColumnStyles. When the Form containing the DataGrid is made visible the initial rows of the DataGrid's DataView source display as one might expect....
2
10190
by: mmdst23 | last post by:
I'm working on a video player app, and I want to implement a trackbar that behaves like the one in Media Player, that is the cursor position moves to where the user clicked instead of moving in that direction by a fixed value. Has anyone implemented something like this before? I haven't found anything on codeproject, or searching the .NET newsgroups. This seems like it would be a common control type, am I missing the easy solution? I...
3
5863
by: MrNobody | last post by:
I have a mystery where my scrollbar behaves differently from when I use it's slider/arrow keys compared to when I manipulate it's value with a onMouseWheel event... When I manipulate my scrollbar's controls (the slider or the arrow key) to go to the bottom, Once it reaches the bottom and cannot go any further I somehow lose 9 pixels of height, so when it refreshes my image the bottom 9 pixels are clipped off. But if I use my...
1
8056
by: 123456prakash | last post by:
Does anyone know if it is possible to set programmatically the position of a JScrollPane vertical scrollbar slider? I load a some components like textfield editorpane labels etc into a panel wrapped in a JScrollPane. The vertical slider follows the length of the components but I want on load the beginning of the panel to be visible and not the end. ie the slider is always at the bottom or in the middle not in the begining I mean, I don't...
3
4976
by: Nebulism | last post by:
Hi everyone, I am working on a module for my GUI that shows one image with an index value below and would use a scrollbar to control which of the images are displayed. The images are stored in a successive folder in the format Pic#, i,e. Pic1, Pic2 etc. What I want to do is make a slider that is attached to a label which would output the slide number that is being looked at. I would use that number then to return the image of the slide...
0
9595
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.