|
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;
}
}
|
|
|
|
|
The real issue is not this code, it's the code that does the drawing. How do you draw your shapes ?
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 )
|
|
|
|
|
Thanks for answering but I am controlling my own paint method and have override the OnPaint mehtod.
|
|
|
|
|
Hi, all;
(Using VS 2008, Win XP Prof SP2)
I was updating a spell-check control that used the MS Word spellchecker when I came across that for .NET 3.0 and above, the RichTextBox (and the regular one, too) have real-time spell checking.
After adding the WPF reference and the System.Windows.Cotrols namespace, I still can't get anything but an error when I try to enable the feature via:
richTextBox.SpellCheck.IsEnabled = true;
Even though its listed in the documentation for the RichTextBox control, SpellCheck is not considered a member if the class.
Much searching and I found this reference: http://msdn2.microsoft.com/en-us/library/ms788728(VS.85).aspx for "How to: Enable Spellchecking in a Text Editing Control" which gives an example - seems simple enough but it just won't work. See Below
Has anyone gotten this to work?
Thanks,
Balboos
(The above link will display the following:
<code>using System;
using System.Windows;
using System.Windows.Controls;
namespace SDKSample {
public partial class SpellCheckExample : Page {
public SpellCheckExample() {
StackPanel myStackPanel = new StackPanel();
//Create TextBox
TextBox myTextBox = new TextBox();
myTextBox.Width = 200;
// Enable spellchecking on the TextBox.
myTextBox.SpellCheck.IsEnabled = true;
// Alternatively, the SetIsEnabled method could be used
// to enable or disable spell checking like this:
// SpellCheck.SetIsEnabled(myTextBox, true);
myStackPanel.Children.Add(myTextBox);
this.Content = myStackPanel;
}
}
}</code>
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"How do you find out if you're unwanted if everyone you try to ask tells you to go away?" - Balboos HaGadol
<div class="ForumMod">modified on Thursday, March 6, 2008 3:47 PM</div>
|
|
|
|
|
Yup - it works for me. Try to use System.Windows.Controls.RichTextBox as the source rather than the WinForms version, as this is a WPF feature.
|
|
|
|