|
Whipped this up in about 20 minutes. (I couldn't wrap my brain around the stinking math for a little while!)
Create a new UserControl, call it ScrollablePicture or whatever. Drop a Panel on the design surface and set its Dock property to Fill, then it's AutoScroll property to True. Drop a PictureBox control on the Panel. You don't have to change any of it's properties.
Then:
public class ScrollablePicture {
private Point m_CursorOffset;
private int m_CurrentHScroll;
private int m_CurrentVScroll;
private bool m_Scrolling = false;
public ScrollablePicture() {
InitializeComponent();
this.Cursor = Cursors.Hand;
}
public Image Image {
get {
return PictureBox1.Image;
}
set {
if (value != null) {
PictureBox1.Size = value.Size;
PictureBox1.Image = value;
}
}
}
private void PictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
if ((e.Button == Windows.Forms.MouseButtons.Left)) {
m_CursorOffset = Panel1.PointToClient(System.Windows.Forms.Cursor.Position);
m_CurrentHScroll = Panel1.HorizontalScroll.Value;
m_CurrentVScroll = Panel1.VerticalScroll.Value;
m_Scrolling = true;
}
}
private void PictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
if (m_Scrolling) {
Point Offset = Panel1.PointToClient(System.Windows.Forms.Cursor.Position);
int newH = (m_CurrentHScroll
+ (m_CursorOffset.X - Offset.X));
int newV = (m_CurrentVScroll
+ (m_CursorOffset.Y - Offset.Y));
if ((newH < Panel1.HorizontalScroll.Minimum)) {
newH = Panel1.HorizontalScroll.Minimum;
}
else if ((newH > Panel1.HorizontalScroll.Maximum)) {
newH = Panel1.HorizontalScroll.Maximum;
}
if ((newV < Panel1.VerticalScroll.Minimum)) {
newV = Panel1.VerticalScroll.Minimum;
}
else if ((newV > Panel1.VerticalScroll.Maximum)) {
newV = Panel1.VerticalScroll.Maximum;
}
Panel1.HorizontalScroll.Value = newH;
Panel1.VerticalScroll.Value = newV;
}
}
private void PictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
m_Scrolling = false;
}
}
* Code coverted from VB.NET to C# by CarlosAg.net[^]
Dave Kreskowiak
Microsoft MVP - Visual Basic
-- modified at 16:21 Thursday 13th July, 2006
|
|
|
|
|
A grat big thanks to everyone who replyed !!!!
It now works perfectly !
Thanks
|
|
|
|
|
I have a page redirect in which I pass a variable. I'd like to pass two, but not sure on the correct syntax. Here is what I have currently:
Response.Redirect ("Add_Cost.aspx?strPartNumberInputReference=" + strPartNumberInputReference);
Can someone help me with the correct syntax?
Thanks!
|
|
|
|
|
Query string paramaters are seperated by &
mypage.aspx?var1=1&var2=2&...
|
|
|
|
|
I like an own ToolStripItem trackbar that acts like a TrackBar. Can’t find any artickle how to do that…
All tips are welcomed!!
_____________________________
...and justice for all
APe
|
|
|
|
|
d00_ape wrote: All tips are welcomed!!
How about looking at the source code to one of the "control" ToolStripItems, e.g. the ComboBox one in Reflector. Then just code something similar but using a trackbar instead.
The Welsh will always support two teams: The Welsh, and anyone playing England
|
|
|
|
|
How do I convert a System.Drawign.Color to RGB int value?
_____________________________
...and justice for all
APe
|
|
|
|
|
See this:
int valueInRGB = Color.Red.ToArgb();
|
|
|
|
|
...no, but I made it with Microsoft.VisualBasic.Information.RGB(...)
ToArgb() returns the ARGB value
_____________________________
...and justice for all
APe
|
|
|
|
|
The A is almost always going to be 255, and therefore be irrelevant. Color doesn't HAVE an A. The alpha tells you how strongly the color is blended with the background. So if it's 255, you can ignore it. If it's not, I guess you can scale the values according to how they'd draw over white or black, if you really want to.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Yeah... that's right.
If you set A to 255, then you will see always the color.
If you set A to 0, then you cannot see the color.
To take only the RGB value, just do this:
int onlyRGB = Color.Red.ToArgb() & 0x00FFFFFF;
|
|
|
|
|
Hi guys,
I need some help! Is there a way to run a store procedure or a .SQL file when running a setup of an application designed in Visual C#. I have already created a windows installer setup in Visual studio and I have an SQL file that I would like to run during installation.
Please help!
sasa
|
|
|
|
|
I don't think you can do it from an MSI. Your SQL script can't be executed, it doesn't know what to connect to, for a start. You could write an exe that runs as a post install step and runs the script on the DB that I assume you know will be there.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I know it can be done, look at the ASPX Starter Kits. I just don't know how they do it, never looked into it. Probably with the MSI SDK, not Studio.
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
Thank you Christian for your answer. I appreciate you taking the time on this. I will probably run the sql statement in manual setup.
sasa
|
|
|
|
|
hi all,
i dont want my exe to start more than once if it's started before.
let's say i start my program and minimize it to taskbar.
if i click on its exe again, it first should check whether it was started before or not. if started before, just maximize it again. if not started before, then should start my application...
how can i do this ?
help me please.
thanks in advance, bye.
|
|
|
|
|
I usually use something like this:
Process[] sameProcesses = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
if(sameProcesses.Length == 1)
{
}
else
{
}
|
|
|
|
|
|
Hi,
I'm trying to create some code to enter a new record into a dataset that was filled from a database that has an autoincremented field. I need to create a unique number to insert into that field in the dataset.
I've already come accross some examples on how to do this that appear complicated - at least to me they are
Surely there is a simple was to retrieve the value of a datasets field eg
variableA = datasetName.tableName.rowNumber.filedName.value
Using the above I could read each row and incrementing variableA until such time as variableA was the highest number in the autoincremented field.
If there is an easier way to generate a unique number to use in the dataset then please let me know BUT I would also like to know the easiest way to read a dataset's specified row value.
TIA
Glen Harvy
|
|
|
|
|
Are you just needing the number to insert into the dataset or are you wanting to update the database with the new record?
|
|
|
|
|
Hi,
I just need to ascertain the value contained within field in the row. I can ascertain the row and even identify it with a SELECT but how can you just get one value from the whole record easily?
Thanks,
Glen Harvy
|
|
|
|
|
Is that record always going to be in the same column of the grid? (I assume yes)
|
|
|
|
|
Does it matter?
Glen Harvy
|
|
|
|
|
Bit of an odd one here. I have the following string:
4e554c4c00
Which is a HEX representation of
NULL
I need to convert that intial string into it human readable format, does anybody know of any framework methods/classes to do this? If not can anybody think of an elegant/quick solution?
I was initially thinking of string parsing, however this portion of code will be called 100's of times a second and parsing string is fairly heavy.
-- modified at 9:17 Thursday 13th July, 2006
EDIT :
Here is a chunk of code that works, however I have a few concerns about speed
string raw = "4e554c4c00";
raw = "556e6b6e6f776e204576656e742025545241504944252e00";
string[] rawParts = new string[raw.Length / 2];
int rawPos = 0;
int partsPos = 0;
while(rawPos < raw.Length)
{
rawParts[partsPos] = raw.Substring(rawPos, 2);
partsPos++;
rawPos++;
rawPos++;
}
string humanReadable = string.Empty;
for(int partsLoop=0; partsLoop<rawParts.Length - 1; partsLoop++)
{
char charPart = Convert.ToChar(
Int32.Parse(rawParts[partsLoop],
System.Globalization.NumberStyles.HexNumber));
humanReadable += charPart.ToString();
}
Console.WriteLine(humanReadable);
if the first value of the string "raw" is used "NULL" is output by the final Console.WriteLine. if the second value of the string is used "Unknown Event %TRAPID%." is output.
-- modified at 9:23 Thursday 13th July, 2006
|
|
|
|
|
MrEyes wrote: I need to convert that intial string into it human readable format
What do you mean by human readable? What do you want it to say? Do you just want your hex string replaced with "null"? In that case:
string humanReadable = inputString.Replace("4e554c4c00","NULL");
|
|
|
|