|
You can create a bitmap, make a graphics object for it, do your drawing and finally save the bitmap to a file:
<br />
using System.Drawing;<br />
using System.Drawing.Imaging;<br />
<br />
Bitmap b = new Bitmap(requiredWidth, requiredHeight);<br />
using (Graphics g = Graphics.FromImage(b)) {<br />
g.FillRectangle(...);<br />
g.DrawString(...);<br />
}<br />
b.Save("C:\\bla.jpg", ImageFormat.Jpeg);<br />
|
|
|
|
|
Huge thanks for both of your ideas!
I already tried to do a screenshot which sorta worked - it shot my complete desktop (which is an easy-to-solve problem) and I had the popup on top of my picture, which is not too great
Right at the moment, I create my Graphics object out of a panel like this:
Graphics g = pnl_painting.CreateGraphics();
Is it possible to create a bitmap and the graphics object like you said, save it AND draw the bitmap in that panel?
Or I could actually create that bitmap on the fly (I save all the needed data in ArrayLists) and leave the rest unchanged, mhm ...
One more thing: how can I export an image to an excelsheet? TIA
|
|
|
|
|
You could do the following:
1. Create a bitmap with the same size as your panel
2. Get a Graphics object of your bitmap with Graphics.FromImage
3. Do your drawing on this Graphics object
4. Save the bitmap with Save
5. Make the Graphics object of your panel (pnl_painting.CreateGraphics())
6. Call DrawImageUnscaled(bitmap, 0, 0) on it
If you leave step 4 out the panel will still be painted correctly but just no file will be created.
With your question regarding excel I cannot help you, but if I remember right there has to be a very good article about automating ecxel here on codeproject.
|
|
|
|
|
Ok, I will check that article out!
Thanks a lot!
|
|
|
|
|
I have a richTextBox control that I load text files into. What is the best way to format and align the text loaded. Also, which control is best to use for this purpose, textBox or richTextBox.
|
|
|
|
|
A TextBox doesn't have a concept of alignment, so you'll have to use the RichTextBox. There's a SelectionAlignment property that does just what you want.
Regards,
mav
|
|
|
|
|
How can I add a DataRowCollection directly into a DataTable? Is there a way besides looping through all the datarows and adding each row to datatable?
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
Not sure what you're asking here. Do you mean you have a DataRowCollection from one table, and you'd like to add its contents to another table? If so, why? Are you cloning a datatable or something?
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Ok I have a server that is listening for incoming requests on ports 9000 through 9010.
That being said, here is the quandry I have. If two people happen to grab port 9005, would the first person to get there lock it down. I mean if the second person gets there at the same time how can I direct the client app to try to reconnect on an other port.
Any ideas or sample code would be welcome.
|
|
|
|
|
Only one socket can listen on a particular port. But more than one socket can connect to a single port. From your question, it is not clear whether you meant the first or the second.
In the first case, the call to Listen() will fail with an exception.
Regards
Senthil
My Blog
|
|
|
|
|
Try reading on "non-blocking server socket" in the MSDN.
The thing is: if you have a "server loop" which waits on data to arrive on any of these ports, then does some manipulation and loops, you will always have poor performance, as your application will block until you are done with one of the requests.
If you decided to use 10 ports in order to offer "10 parallel connections", you totally misunderstood the concept (sorry ).
You should only use different ports for different services (e.g. FTP Control connection on Port 21, HTTP on Port 80, ...) or to seperate user-groups (e.g. Customer1 connects to FTP on port 21, Customer2 uses Port 23, ...).
Specifically, you might want to read into Delegates, Callbacks, etc. These are, IMHO, the easiest way to create socket-using apps without doing manual multithreading.
Cheers
Sid
|
|
|
|
|
I have a web form, which has a place holder named Example when, Page_Load happens in my web form. I’m creating dynamically a WUC named WebUserControl3 into my place holder.
WebUserControl3 has several text boxes, a button and a label, when user click button I’m executing some calculation which result I’m placing into label. But when user click button occurs Page_Load in web form that contains my place holder and I need recreate my WUC plus data was contained therein, I have tried with ViewState and Session variables but still I can’t pass data from WUC to web form to recreate WUC and its data. Obviously WUC is created again without data. Notwithstanding if I re-enter data in WUC and click button again data are displayed OK.
Why first time it isn’t working and begin second try it’s working fine?
My code is:
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
}
else
{
Example.Controls.Clear();
Control control = this.Page.LoadControl("WebUserControl3.ascx");
Example.Controls.Add(control);
}
}
Thanks in advance
A.L.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
Does somebody know about this topic?
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
Hello:
At last I found a solution.
For some reason the page does not create it with the same control Id. the first time as every other time.
To solve it I inserted this line:
control.ID="WebUserCotrol3"; as it shows:
Example.Controls.Clear();
Control control = this.Page.LoadControl("WebUserControl3.ascx");
control.ID="WebUserCotrol3";
Example.Controls.Add(control);
I hope this be useful for newbie person as I am.
Greetings.
A.L.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
How can I inside Windows Form code determine if there has been key strokes or mouse move outside of the Form.
e.g. To make a Sys Tray application that can determine if the user has left the pc compliatly
(If there has been no mousemove or key strokes for a period)
|
|
|
|
|
|
I'm attempting to send Keyboard and Mouse events to windows other than my own using the SendMessage and/or PostMessage APIs. I've looked pretty closely at the messageboards here and am still having a hell of a time getting it to work.
[DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr FindWindow(string winClass, string WinName);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
private const uint WM_ACTIVATEAPP=0x001C;
private const uint WM_KEYDOWN= 0x0100;
private const uint WM_KEYUP=0x0101;
private const uint WM_SETFOCUS=0x0007;
private void CheckWindows()
{
IntPtr WinHandle=IntPtr.Zero;
WinHandle = FindWindow(null,"Untitled - Notepad");
if(WinHandle!=IntPtr.Zero)
{
SendMessage(WinHandle,WM_ACTIVATEAPP,(IntPtr)1,IntPtr.Zero);
SendMessage(WinHandle,WM_SETFOCUS,IntPtr.Zero,IntPtr.Zero);
SendMessage(WinHandle,WM_KEYDOWN,(IntPtr)0x31,(IntPtr)1);
SendMessage(WinHandle,WM_KEYUP,(IntPtr)0x31,(IntPtr)1);
}
}
At this point I assume I'm not sending the correct messages, but I was hoping someone could point me in the right direction.
|
|
|
|
|
First, make sure you're using the correct signatures (it looks like you are already, but just in case, use pinvoke.net)
Also, use the Spy++ tool bundled with Visual Studio to see correct messages to send to the app. For example, use Spy++ to view the incoming messages when you type some text in Notepad. After logging the necessary messages, you should be able to send the same messages using your app.
I just tried this and it looks like a key press in notepad generates:
WM_KEYDOWN
WM_CHAR
EM_GETSEL
EM_GETSEL
EM_LINEFROMCHAR
EM_LINEFROMCHAR
EM_LINEINDEX
EM_LINEINDEX
WM_KEYUP
You might want to try those messages, in that order, to send text to Notepad.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lies of Our Fathers: A Must-Know About Lent
Judah Himango
|
|
|
|
|
I did already use Spy++ to log the messages. I just didn't know if all these messages needed to be sent or if some are generated as a result of initial messages...ie. WM_ACTIVATEAPP. I also could not tell what message were generated by NOTEPAD as a result of the WM_KEYDOWN and WM_CHAR messages that most likely were generated by the keyboard. Thanks for the input though.
|
|
|
|
|
If you don't want to mess with sending each message/character separately or have problems getting it to work, you could take a look at the SendKeys class in the FCL.
It has easy to use static methods for this.
Regards,
mav
|
|
|
|
|
Right, but you must make sure the window is topmost and has the focus. I chose the SendMessage to avaoid this.
|
|
|
|
|
I'm trying to load an assembly dynamically (IE. extracting it as an embedded resource, and then using Assembly.Load() to load it) and then use the types and functions that are built into it, but I can't figure out how to get access to them, nor could I find any good tutorials.
Any hints, or am I trying the impossible?
|
|
|
|
|
You can use Assembly.Load or Assembly.LoadFrom(). Those function will return you an Assembly object. You can then call GetTypes() on that object to get the list of all types. For each Type object, you can then call Activator.CreateInstance() to create an instance and then Type's InvokeMember() to call methods. Something like
<br />
Assembly assembly = Assembly.Load("...");<br />
foreach(Type t in assembly.GetTypes())<br />
{<br />
Object obj = Activator.CreateInstance(t);<br />
t.InvokeMember("MyMethod", BindingFlags.Instance, null, obj, null);<br />
}<br />
Hope this helps.
Regards
Senthil
My Blog
|
|
|
|
|
I wrote a FTP program that would download files from a ftp server and store it on my machine.
Then on my other pc, I mapped the location of that program and run it (2 pcs are on the same network)
I got this error message:
Unhandled Exception: System.Security.SecurityException: Request for the permissi
on of type System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5
000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
at System.Security.CodeAccessSecurityEngine.CheckTokenBasedSetHelper(Boolean
ignoreGrants, TokenBasedSet grants, TokenBasedSet denied, TokenBasedSet demands)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet gran
ts, PermissionSet denied, PermissionSet demands)
at tieFtpv2.CExecute..ctor(Boolean display, String command, CXmlDoc myProfile
, Int32 myIndex)
at tieFtpv2.CTieFTP.Main(String[] args)
The state of the failed permission was:
<ipermission class="System.Security.Permissions.FileIOPermission, mscorlib, Vers
ion=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
="" version="1" unrestricted="true">
Could anyone please help me out?
What do i need to do with the Security to be able to run the program on a network?
Thank you so much in advance.
|
|
|
|
|
Thats caused by CAS (Code Access Security). You need to change the policy for the appropiate zone to allow this. This can be achieved by using the wizard in administrative tools, or by the command line tool caspol. More details can be found by googling.
--
Joel Lucsy
|
|
|
|
|