|
And you are sure you have offset the Rect properly to compensate?
"You get that on the big jobs."
|
|
|
|
|
Hi everyone.
I have drawn a square on the screen/form using GDI. Now I want to move this object around using keyboard inputs. I just want it to move along the x-axis using left and right arrow keys. I can assign the keys but the problem is making that object move. You help on this is highly appreciated.
|
|
|
|
|
How you move it is going to depend to a large extent on how you drew it / are drawing it.
The basics are pretty obvious though: two integers, one for X and one for Y. Up key decreases Y value, Down increases it. Left key decreases X, right increases.
But there are three common ways to draw a rectangle:
1) On a panel or similar control. In this case, use the new X and Y values on the Panel.Location to move it.
2) On the form via the Paint event: In your Paint handler, use the X and Y to set the top left position of the rectangle. When you modify X or Y, use the Form.Invalidate method to force a re-draw.
3) On the form via getting a graphics context for the form and using Graphics.DrawReactangle. In this case, don't. Use method 2 instead. Trust me on this!
If you have used another method, tell us what it is!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: Trust me on this!
Only a fool would not.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
|
OriginalGriff wrote: the nicest thing anyone said to me all day!
It's only 11 o'clock.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
Thank you.
I got it just after sending this message. I used the option 2.
|
|
|
|
|
Capture the information about the new coordinates based on key presses, then in your OnPaint() method you redraw the object at the new coordinates. Something like:
OnKeyPress(int key)
{
if (key == LEFT)
pointx -= 1;
if (key == RIGHT)
pointx += 1;
}
OnPaint()
{
DrawSquare(pointx, pointy);
}
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
Thank you.
|
|
|
|
|
|
Got it. Its understandable to take this long for someone who is learning the new language like me. Thank you anyway.
|
|
|
|
|
HI All,
I Want to read an image that contains a data formatted as table in this image using MODI OCR, but when i red the image the returned text not formatted correctly.
this is a sample table saved as a picture
A5 A4 A3 A2 A1 Q.#
1 1 1 1 1 -1-
2 2 2 2 2 -2-
3 3 3 3 3 -3-
4 4 4 4 4 -4-
5 5 5 5 5 -5-
Please help me if you can.
|
|
|
|
|
zead wrote: Please help me if you can.
I'd like to help, but I don't know what your question is.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
HI,
I have an image that contains a text as table (columns and rows data) ,
I want to use OCR or MODI to read this text from image and write it in excel file as a columns.
My Question is how to use the Office MODI or any OCR libraries with .Net to do that.
Thanks
|
|
|
|
|
I am developing desktop application.Front end:Visual studio 2010.
Is it possible to change the color(foreground & background) of only selected item in the ListBox?
is this possible with mousehover event?
Please suggest the better solution
|
|
|
|
|
I'm not sure if you can do it in the way you ask, but you can use the OnDrawItem() [^] event to do your own drawing of the items.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
In this article[^] an OwnerDrawn ListBox is used to control the colors.
|
|
|
|
|
You have to either use an owner draw list box or a custom control[^] (shameless self-promotion).
|
|
|
|
|
Hallo
i get this Error when i try to load an Ax. has any one any idee?
Error:
Unable to get the window handle for the 'MyAx' control. Windowless ActiveX controls are not supported.
OS:
Windows 7 32Bit
Visual Studio 2010
modified 29-Apr-12 7:18am.
|
|
|
|
|
|
Hello,
I've a question about xmlSerializer in C#,
My question is how can you create an xmlfile with the xmlserializer from two or more different objects without creating a class contains all those objects.
For example this is the xml file wanted:
="1.0"="UTF-8"
<Root>
<Books>
<Book>
<Title>X</Title>
<Author>Mr x</Author>
</Book>
</Books>
<Movies>
<Movie> Movie Y</Movie>
</Movies>
</Root>
At the moment I'll do this with the XDocument class and create for each property an Xelement.
For example I create an XElement books which contains child elements and add them all to an XDocument and save this XDocument object.
public XElement getBooksElement(List<Book> books)
{
XElement ret = new XElement("Books");
foreach(Book b in books)
ret.Add(getBookElement(b));
return ret;
}
public XElement getBookElement(Book book)
{
XElement ret = new XElement("Book");
ret.Add(new XElement("Title", b.Title));
ret.Add(new XElement("Author", b.Author));
return ret;
}
How can be this achieved without creating a class containing all elements which should be in the object but serialize each object to an xml part and add those to the xml file.
I hope my question is clear enough,
Thank you in advance.
|
|
|
|
|
So you want to serialize each object individually, without creating a container class to hold all the objects? How about if you serialize each object to a MemoryStream, then create an XElement or XDocument to contain them all, and stick all the data you saved into the MemoryStreams inside it?
|
|
|
|
|
Yes that's sounds like a good idea but how do I create a XElement or XDocument out of the memorystream, and how can I manage the deserialization of this? Because should I read the XDocument and divide this XDocument in multie memorystream for dividing this up?
|
|
|
|
|
You can use the XDocument.Load static method to create an XDocument from the stream. (You might need to call Seek on the stream to reset it to the beginning!) As for creating multiple MemoryStreams to load the XDocument's elements, you can do this:
foreach (var element in myXDocument.Elements())
{
var ms = new MemoryStream(Encoding.Unicode.GetBytes(element.ToString()));
}
|
|
|
|
|
I don't really have a big issue with the powershell working because it works just fine.
The problem I'm having is the method exits before the command is actually completed on the Exchange server. I think it may have something to do with the way Exchange throttles powershell commands.
Is there a way to use powershell with Exchange but have it completely wait until the command is finish before refreshing my page?
Let me give you an example:
A user logs into the web interface and decides to enable their user for Exchange. So the user clicks Enable Exchange. This fires a powershell to Exchange running the Enable-Mailbox command. After it completes the command it retrieves updated information from Active Directory / Exchange about the users mailbox.
The problem I have is when it tries to retrieve the updated information it hasn't had time to populate in Exchange so it still thinks there isn't a mailbox. I know I could put a sleep in there but I rather do something cleaner.
Here is my base class:
public void RunPowershell(PSCommand pscmd = null, String script = null)
{
Runspace remoteRunspace = null;
PSDataCollection<ErrorRecord> errors = new PSDataCollection<ErrorRecord>();
OpenRunspace(_uri, _schema, _username, _password, ref remoteRunspace);
remoteRunspace.Open();
powershell.Runspace = remoteRunspace;
powershell.Streams.ClearStreams();
powershell.Commands.Clear();
if (pscmd != null)
{
String debugLog = "[RunPowershell] Executing powershell: ";
foreach (Command cmd in pscmd.Commands)
{
debugLog += cmd.CommandText;
foreach (CommandParameter cp in cmd.Parameters)
debugLog += String.Format("-{0} {1}", cp.Name, cp.Value.ToString());
}
Log.Debug(debugLog);
powershell.Commands = pscmd;
}
else if (script != null)
{
Log.Debug("[RunPowershell] Executing powershell: " + script);
powershell.Commands.AddScript(script);
}
powershell.Invoke();
ThrowIfError();
Log.Debug("[Exited] RunPowershell");
}
private void OpenRunspace(string uri, string schema, string username, string password, ref Runspace remoteRunspace)
{
SecureString securePass = new SecureString();
foreach (char c in password.ToCharArray())
securePass.AppendChar(c);
PSCredential psc = new PSCredential(username, securePass);
WSManConnectionInfo wmci = new WSManConnectionInfo(new Uri(uri), schema, psc);
wmci.AuthenticationMechanism = AuthenticationMechanism.Basic;
remoteRunspace = RunspaceFactory.CreateRunspace(wmci);
}
Here is the command running Enable-Mailbox:
public void Execute()
{
try
{
if (String.IsNullOrEmpty(Identity))
throw new Exception("Identity must be specified.");
if (String.IsNullOrEmpty(Alias))
throw new Exception("Alias must be specified.");
if (String.IsNullOrEmpty(DisplayName))
throw new Exception("Display Name must be specified.");
if (String.IsNullOrEmpty(PrimarySmtpAddress))
throw new Exception("The Primary Smtp Address must be specified.");
if (String.IsNullOrEmpty(CompanyCode))
throw new Exception("The Company Code must be specified.");
String enableMailboxCmd = String.Format(@"Enable-Mailbox -Identity '{0}' -AddressBookPolicy '{1} ABP' -Alias '{2}' -DisplayName '{3}' -PrimarySmtpAddress '{4}';",
Identity, CompanyCode, Alias, DisplayName, PrimarySmtpAddress);
String setMailbox = String.Format(@"Set-Mailbox -Identity '{0}' -OfflineAddressBook '{1} OAL' -CustomAttribute1 '{2}' -IssueWarningQuota:{3}KB -ProhibitSendQuota:{4}KB -ProhibitSendReceiveQuota:{5}KB -UseDatabaseQuotaDefaults $False;",
Identity, CompanyCode, CompanyCode, WarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota);
String setCasMailbox = String.Format(@"Set-CASMailbox -Identity '{0}' -ActiveSyncEnabled:${1} -ActiveSyncMailboxPolicy '{2}' -IMAPEnabled:${3} -POPEnabled:${4} -MAPIEnabled:${5} -OWAEnabled:${6} -OWAMailboxPolicy '{7}';",
Identity, ActiveSyncEnabled.ToString(), ActiveSyncPolicy, IMAPEnabled.ToString(), POPEnabled.ToString(), MAPIEnabled.ToString(), OWAEnabled.ToString(), OWAPolicy);
this.RunPowershell(null,
enableMailboxCmd +
setMailbox +
setCasMailbox);
}
catch (Exception ex)
{
throw ex;
}
finally
{
this.Close();
}
}
Thank you for your help
|
|
|
|