|
sagedread wrote: how would you search for the string representing the favicon.ico path?
In .NET 1 and .NET 2, you'd write it like this:
string iconFilePath = "";
string iconFileLabel = "IconFile=";
foreach (string line in File.ReadAllLines(theFavoriteFilePathGoesHere))
{
if (line.StartsWith(iconFileLabel))
{
iconFilePath = line.Remove(0, iconFileLabel.Length);
break;
}
} Or if you're using the latest version of .NET, you could write this as a LINQ query:
var matchingLines = from line in File.ReadAllLines(favoriteFilePath)
let iconFileLabel = "IconFile="
where line.StartsWith(iconFileLabel)
select line.Remove(0, iconFileLabel.Length);
var iconFilePath = matchingLines.FirstOrDefault();
|
|
|
|
|
Hello,
I'm trying to pass an array of a type I've defined to unmanaged C++.
If I declare the parameter as: func (BitmapInfo* objects...
I get the error: "Cannot take the address of, get the size of, or declare a pointer to an unmanaged type." (This is even with BitmapInfo declared with the "unsafe" attribute.)
If I declare it as: func (BitmapInfo [] objects...
It compiles, but crashes with the message: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
If I try to put the address in an IntPtr:
IntPtr arrayStart = (IntPtr) (&(objects [0]));
I get the first compile error again.
How can I pass a custom array to unmanaged code? Thanks!
|
|
|
|
|
Never mind -- I solved the problem. Here's the solution in case anyone else encounters this:
The key idea is to use a struct instead of a class. The reason is that class instances are allocated in the heap, and the managed environment moves heap items around, so any pointer to a class instance may become invalid.
Structs are allocated on the stack and stay there, so it's feasible to use pointers to them.
|
|
|
|
|
For reference types (classes) you would need a GCHandle that allows you to fix the object
in memory, get its IntPtr, use it, then free it again.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
|
Hi guys
I have a rdlc report which displays an image from a database. I have no problem displaying the image. What i do have a problem with is that the image always shows in the top left corner of my picture box, does anyone know how to center the image vertically and horizontally.
Thanx in advance
|
|
|
|
|
Hi,
Take a look at the SizeMode property and specify PictureBoxSizeMode.CenterImage
"The image is displayed in the center if the PictureBox is larger than the image. If the image is larger than the PictureBox, the picture is placed in the center of the PictureBox and the outside edges are clipped."
AlanN.
|
|
|
|
|
Thank you for the reply Alan
I have set the Sizemode property to AutoSize so that the image that i get from the db displays proportionally. I do not want the picture scaling to be distorted.
|
|
|
|
|
My question isn't exclusive to C# , it applies to any language that can use system api's..
here goes..
I'm writing a driver for a USB device a friend of mine pieced together..
All's well up to one point.. the thing registers certain events , and i have to send keystrokes accordingly so , to be system friendly (I'm quite a friendly person) I use the recommended SendInput function in User32.. still no problems here..
BUT , i have a software K(v)M switch running ( i use multiplicity but i used to use synergy , but thats not important) , the important thing is , it doesn't register the keys i press using the SendInput function...
So i was wondering ..
1 can someone say with absolute certainty how they do it...
2 i presume they use a SetWindowsHookEx with low level keyboard intercepts , and when I'm on the second screen , they probably return a dummy value on CallNextHookEx ... (still that doesnt explain why they aren't fooled by SendInput)
3 Can i also put in a hook in my program , bump it above the hook set by the kvm software(no idea if that's possible ), and use the callback function to simulate key presses...
If anyone has any suggestions about this please feel free to reply , any reply is welcome.
Thank you in advance.
|
|
|
|
|
You can try using keybd_event, thats like putting the keyboard data into the buffer yourself, rather that it getting sent from the keyboard. The key presses will be sent to the active window / control though, so you don't have as much control over where it goes.
keybd_event[^]
I think there's also an article on CP illustrating how to use keybd_event in C#
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
I started reading about it before , but i stopped when i read
"Windows NT/2000/XP/Vista:This function has been superseded"
By which i sort of understood the function's days were numbered ..
Does this function influence the lowest keyboard input related layer in the OS , before i have to start messing with memory , and reserve or map memory before the OS is loaded..
Anyway , ill have a go , and see what it gives , thnx for the suggestion.
modified on Tuesday, April 15, 2008 4:08 PM
|
|
|
|
|
Negative on keyevent ..
Pffffffff........
I have no idea where to start looking now..
-Make a virtual HID device .....
-Make a memory mapping of the bios keyboard area somewhere at the end of vmem space to access from OS. by making some kind of boot loader..
-Buy some chinese feller from a sweatshop and make him press certain keys when he gets electric shocks in certain places.. ( response time would be a gradually incrementing feature )
I am still inclined to think the kvm software has a hook set up somewhere , and i need to feed it keys from the callback above.. tho i have no good feeling about sending a callback without having gotten a key in the first place..
Or maybe i should try the C++ section..
Any reply is welcome
Kind regards.
|
|
|
|
|
mumble mumble ..
any of you have experience modifying DDK's VHIDMINI driver ...?
i guess i'll ask in C++
..
|
|
|
|
|
How can I refresh or update ParentForm from ChildForm?
|
|
|
|
|
You probably could use this.Parent.Refresh()
or this.MdiParent.Refresh() if you have an MDI child form
|
|
|
|
|
I think I need to make a reference to a parent form first, and then use Refresh(). Any idea how to do that?
|
|
|
|
|
Note quite sure I understand what you mean ...
|
|
|
|
|
I have two forms. One is ParentForm, and on it is a databind combobox. There is also a button, and when the user clicks it, it takes him to another form where he can enter some new information and add those information to a datasource to which my combobox is connected to. That information should then be displayed in combobox, but I need to refresh it first, and I have no idea how to do that.
The point it, I need to refresh combobox or the entire ParentForm.
|
|
|
|
|
If you created an instance of your and displayed a form (FormB) from FormA. Then the property FormB.Parent would be set to FormA (you can also set this yourself to any form)
Therefor by calling this.Parent.Refresh(); from your child form, your main form should be updated.
If your combobox still isn't updated, then you'll have to write a public method on your main form that updates the combobox. Then you can call the method from the child form by whatever means you know how.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
ok, you didn't say anything about data, I thought you just want to refresh the form .. anyways, the dirty solution is to reassign the data source that contains the data (whatever that is, a collection or a data table or view) to the datasource of the combobox, I think there's also a method on the data source property that you may call, you may check the documentation for that, so, create a public method in your parent form, something like RefreshComboBox(), and call it from the child form, (don't forget to pass a reference to your parent form in the constructor of the child form) .. the other solution is to bind your combobox to a BindingList (or a class that implements IBindingList), and pass a reference to the binding list to the child form, beware though that whenever the data in the binding list changes the data in the combobox will change regardless of whether the data was saved to the database or not, this will work very well with addition and deletion from the binding list, if you also want the combobox to display modified data, ie. the data of an item was changed, you have to implement INotifyPropertyChanged in the class of the objects contained in the binding list ..
hope this helps...
|
|
|
|
|
All,
I have a main GUI that is a singleton and I am trying to use it in a Background Worker that performs a ShowDialog on a newly created form. The ShowDialog needs and IWin32Window to properly render the new form, how do I "safely" use the main form instance in the ShowDialog? I keep getting [InvalidOperationException] and I am not sure how to use delegates on the entire form rather than a control.
Thanks,
Lawrence
|
|
|
|
|
First, it sounds like you're abusing the BackgroundWorker. The BackgroundWorker is meant for running non-UI work on a background thread. If you want to update the UI during that work, call worker.ReportProgress, which will fire the ProgressChanged event on the UI thread. Also, the RunWorkerCompleted event will fire when the work is done, and it will fire on the UI thread.
If you really have to create forms or controls on a background thread, you must ensure that the thread is STA. Look at Thread.SetApartmentState before you start the thread. You can't make BackgroundWorker threads be STA, so the BackgroundWorker won't work for this.
Ideally, however, you use just a single thread to create and change your UI controls. Without this, you're going to have thread marshalling nightmares if different UIs need to be accessed on different threads.
To sum up, use a background worker to perform non-UI related work on a background thread. If you need to update the UI from this background thread, call worker.ReportProgress and do the UI update inside a worker.ProgressChanged event handler.
|
|
|
|
|
Thanks for your response!!
Ok, so I have moved my functionality to a thread instead of a background worker but I still get the error when I try to ShowDialog(Instance()) with-in my thread where the instance is the Main GUI. How do I invoke the whole form or Instance?
By the way, I did set the SetApartmentState to STA.
Lawrence.
|
|
|
|
|
What does Instance() do? It's hard to diagnose your problem without some source code.
As I said before, I suspect you're approaching this wrong. Let's step back and ask, why do you want to create and show a form on a background thread?
|
|
|
|
|
Instance() returns static instance of the main form in my project..
Ok, I have a thread doing this work because I have a progress bar (marquee) on the main form that displays when potentially time consuming activities are happening. When I Show my new form it holds up the thread and I don’t see my progress bar being updated until after the form comes up. So I decided to kick off that work in its own thread so I can see my progress bar being updated.
If you need anymore info please don’t hesitate to ask.
Thanks,
Lawrence
|
|
|
|