|
I've never given it a second thought.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Usually just east of New Hampshire.
|
|
|
|
|
Hi! I had created a picture box and a button. When I click on the button one circle and one rectangle will be drawn on the picture box. I would like to implement drag and drop effect on the picture box so that both circle and rectangle can be move freely in picture box area. Does anyone know how to implement it? Because I don't have any idea where to start. Thanks in advance for the help.
Here is my code on drawing that 2 shapes in picture box:-
using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace test_drag
{
public partial class Window1
{
private Graphics g;
private System.Drawing.Pen pen1;
Bitmap bitmap;
public Window1()
{
this.InitializeComponent();
bitmap = new Bitmap(pictureBox.Width,pictureBox.Height);
g = Graphics.FromImage(bitmap);
// Insert code required on object creation below this point.
}
private void create_Click(object sender, RoutedEventArgs e)
{
pen1 = new System.Drawing.Pen(System.Drawing.Color.Blue, 1);
g.DrawRectangle(pen1, 10, 10, 50, 50);
g.DrawEllipse(pen1, 10, 80, 30, 30);
pen1.Dispose();
using (Graphics h = pictureBox.CreateGraphics())
{
h.DrawImageUnscaled(bitmap, 0, 0, pictureBox.Width, pictureBox.Height);
h.Dispose();
}
}
}
}
|
|
|
|
|
yuenli wrote: using (Graphics h = pictureBox.CreateGraphics())
This is a disaster, never use it. Open your app, then open calculator. Draw some stuff in your app. Now drag calculator across your app and out again. See how your drawings have disappeared ? That's because you used creategraphics.
The paint event is where you need to do all drawing. You force a paint event by calling Invalidate().
What do you mean by drag and drop ? Whatever you mean, you need to keep your shapes in an array, and iterate over that array to draw them in your paint event. Then you can make one shape your selected shape, and change it's position while forcing a paint, so the shape moves when it's redrawn.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Christian,
Thanks for the reply. Actually I am a newbie. May I know what do you mean by keep shapes in array and draw them in paint event. Do you mean that each time I change a shape location I have to recall the paint event? And How to I make selected shape by allowing user to select it? I wish to do something like Paint application where you can select the drawn shape and move it to new location inside the drawing area. Thanks.
|
|
|
|
|
It sounds to me like you need to start with something more basic.
Your shapes should be represented by class instances. Ideally they'd know how to draw themselves, just taking a graphics object. Yes, calling Invalidate to force a paint event is THE way to make a windows app redraw itself. Then you have your list of shapes and you iterate over them, getting them all to draw themselves. You'd also store the co-ordinates of each one and you'd iterate over them all when the mouse goes down, to work out which one is under the mouse, and mark it as selected.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
That means I only need to play with On mouse up and on mouse down event and everytime call the paint function to reload whole thing. Am I right?
|
|
|
|
|
No, if you're moving the object, you need to repaint in onmousemove, and also move your object by however far the mouse has moved first.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Does that mean in on mouse move function i need to get the x y position of selected shape and repaint the whole drawing? This step is also apply in on mouse up right? Thanks.
|
|
|
|
|
The drawing all happens in OnPaint. What you need to do in the mouse move, is move your shape if the mouse is down, so that it moves the amount that the mouse has moved. Then call invalidate() to force a repaint, which draws the shape in it's new position.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi!
I try to over write the onPaint event handler but it seem that got error. This is because I embeded picture box to windows host form in xaml files. Can anyone help me to solve this problem? Really thanks for the help.
XAML code:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns ="http://schemas.microsoft.com/expression/blend/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="test_drag.Window1"
x:Name="Window"
Title="Window1"
Width="516"
Height="694"
>
<Grid x:Name="LayoutRoot">
<WindowsFormsHost x:Name="host1" Background="#FFE1E0E0" AllowDrop="True" Margin="0,0,92,0" VerticalAlignment="Top" Height="312" >
<wf:PictureBox x:Name="pictureBox" Width="300" Height="300" Paint="pictureBox_Paint" />
</WindowsFormsHost>
</Grid>
</Window>
C# coding:
using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Documents;
using System.Windows.Markup;
namespace test_drag
{
public partial class Window1
{
Font font;
public Window1()
{
this.InitializeComponent();
font = new Font("Arial", 10);
// Insert code required on object creation below this point.
}
private void pictureBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawString("This text is render", font, System.Drawing.Brushes.Red, 0, 0);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawString("this overrride", font, System.Drawing.Brushes.Blue, 5, 5);
}
}
}
|
|
|
|
|
Hi everybody,
been struggling to understand this problem for hours, now im asking the pros...
<br />
OleDbCommand UCommand = new OleDbCommand("UPDATE UniqueDevices SET DeviceName=@'" + NewName + "' WHERE MACAddress=@'" + MACAddress + "'", Connection);<br />
<br />
adapter.UpdateCommand = UCommand;<br />
adapter.UpdateCommand.Connection = Connection;<br />
adapter.Update(ds, "UniqueDevices");<br />
<br />
Connection.Close();<br />
Can anybody please, PLEASE highlight the [possibily] obvious problem here. I live in the UK and its now 2:30am and i really want to go to bed!
On a serious note, please advise.
Thanks
Jonathan Harker
|
|
|
|
|
Omit the @ characters
or (preferably) use parameters.
And you probably don't need the DataAdapter at all; just execute the command.
|
|
|
|
|
thanks alot for your post PIEBALDconsult
your message inspired the answer:
<br />
OleDbCommand UCommand = new OleDbCommand("UPDATE UniqueDevices SET DeviceName='" + NewName + "' WHERE MACAddress='" + MACAddress + "'", Connection);<br />
UCommand.ExecuteNonQuery();<br />
cant believe i missed that one simple command!
once again thanks alot.
Jonathan Harker
|
|
|
|
|
(It's still better to use parameters.)
|
|
|
|
|
You might want to change your SQL statement because it really is subject to SQL injection.
Also I think that instead of adapter.Update that you might want to investigate the ExecuteScalar() method of the OleDbCommand class.
Microsoft provides pretty good documentation on the OleDbCommand class. http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbcommand(VS.71).aspx[^]
Just because we can; does not mean we should.
|
|
|
|
|
While trying to process multiple select statement and retreiving files from my database I get the following message:
"ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x271130
to COM context 0x2712a0 for 60 seconds. The thread that owns the destination
context/apartment is most likely either doing a non pumping wait or
processing a very long running operation without pumping Windows messages.
This situation generally has a negative performance impact and may even
lead to the application becoming non responsive or memory usage accumulating
continually over time. To avoid this problem, all single threaded apartment
(STA) threads should use pumping wait primitives (such as
CoWaitForMultipleHandles) and routinely pump messages during long running
operations."
How do I resolve this problem, I am using C# and SQL Server.
Thanks in advance,
Michael
|
|
|
|
|
|
|
Hi my friends. I'm a newcomer around here and I would like to ask for your help, if it is possible of course. My name is Dimitris and I'm from Greece, so I would appreciate any kind of answer. My questions are:
1)How can I create the following array in C#?
2)How can I sort the jobs according to the Johnson's algorithm?
JOB | PRINT(HOURS) | BINDING (HOURS) | 1 | 15 | 3 | 2 | 7 | 9 | 3 | 4 | 10 | 4 | 7 | 6 | 5 | 10 | 9 | 6 | 4 | 5 | 7 | 7 | 8 |
If you have any kind of code for the above questions, it would be the best for me
Thank you in advance
modified on Thursday, March 6, 2008 6:26 PM
|
|
|
|
|
Two ways seem possible to me ( well, three, but the third is nasty )
1 - create a datatable in memory
2 - this is probably easier - create a class called PrintJob or something that has three properties, and create a List<PrintJob> to hold your data.
Now, I have no idea what Johnsons algorithm is, but I know you can write a class or an anonymous delegate to provide custom sorting on a list.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
DIMITRIS OLGA wrote: How can I create the following array?
It looks like you used HTML.
DIMITRIS OLGA wrote: the Johnson's algorithm
That depends on the size of your Johnson.
|
|
|
|
|
I'd go with Chris G's option 2. But you could also use a 2D array (perhaps his option 3?), although it wouldn't be great for readability... and lots of people i know don't seem too fond of the multidimensional arrays.
I also don't know what Johnsons algorith is either. All i know of the top of my head is the trusty old bubble sort.
My current favourite word is: Nipple!
-SK Genius
|
|
|
|
|
That was my option 3 - the issue is that the data becomes loosly coupled and loosely defined.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi friends, I am trying to move a control on my form when the control is selected and being moved on the screen. The control is moving but the problem is that it's leaving its instances behind while i am moving on form. I don't want to show its skin image. What i want if i move my control from point A to point B i don't wanna calcuate its location in between. How can i show a nice move from Point A to B without regenerating on every location. thanks I shall appreciate
public void ShapControl_MouseMove(object sender, MouseEventArgs e)
{
if (isShapSelected)
{
Location = new Point(e.X - _mousePointed.X + this.Left, e.Y - _mousePointed.Y +this.Top);
}
}
public void ShapeControl_MouseDown(object sender, MouseEventArgs e)
{
isShapSelected = true;
_mousePointed = new Point(e.X, e.Y);
}
public void ShapeControl_MouseUp(object sender, MouseEventArgs e)
{
if (isSymbolSelected)
{
isShapeSelected = false;
}
}
|
|
|
|