|
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
|
|
|
|
|
I think the problem is that you're essentially modifying your main form on a background thread by making it become the owner of a form created on a different thread. This is bound to cause issues.
I guess what I'm saying is, there may not be a way to assign one form to be the owner of another when they're created on different threads. I think that's "illegal" by Win32 UI standards. I could be wrong about that, but I've never seen it done.
There are some alternatives that come to mind, both involve no threads:
- Forcibly update the main form's progress bar during the initialization of the second form. This involves sprinkling mainForm.ProgressBar.Update() calls during the creation and showing of the second form.
- Don't make the showing of the secondary form take so long: don't do any work during initialization, lazily initialize everything you can, wait for Application.Idle event to do anything, etc.
I guess both of those boil down to: find out what's taking long when showing the 2nd form, then spread out that work so it doesn't freeze your main form.
|
|
|
|
|
Thanks for all your help. I will try to force the updates on to the main form from the second form because I can't lazy initialize this time.
Thanks again.
Lawrence
|
|
|
|
|
Tried option 1 and the Main Form will not render the progress bar while it’s trying to load form 2. After form 2 is loaded then I see the progress bar update. I am now back to square 1.
Any other ideas?
Lawrence
|
|
|
|
|
Lawrence, what is the 2nd form doing that causes the UI to freeze? Is it performing a lot of work? Does it have a lot of controls on it?
|
|
|
|
|
Judah, it doesn't have much controls but it's doing a webrequest POST which takes some time.
I think I found a solution; the thread that starts the second form is being launched from a dummy class that inherits from Form. This allows the form to pop up; the only catch is I will have to do some manual work if I want to make it model.
Lawrence
|
|
|
|