I made a GUI using windows forms. Just wondering if it is possible to add a mousehover event for picture boxes (New-Object System.Windows.Forms.PictureBox).
A quick workaround I had made is to create invisible buttons where the picture boxes are and add .add_mousehover and .add_mouseleave events on that button. Rather messy, really.
Any ideas?
You can add the add_mousehover tho your System.Windows.Forms.PictureBox object.
$test = {MSG * 1}
$pictureBox1 = New-Object System.Windows.Forms.PictureBox
$pictureBox1.add_mousehover($test)
Related
I'm creating a simple GUI using Powershell and Windows Forms for a set of scripts I have written.
I've generated a bunch of buttons in the GUI and I'm currently in the process of adding styles to my buttons.
$Button1 = New-Object System.Windows.Forms.Button
Is there anyway to set the below set of lines as a global/default setting of sorts for all buttons?
$Button1.Cursor = [System.Windows.Forms.Cursors]::Hand
$Button1.BackColor = '#CCCC99'
$Button1.Font = New-Object System.Drawing.Font("Verdana",10,[System.Drawing.FontStyle]::Bold)
To give you an idea, what I'm doing now is adding the block of text for every button.
$Button1.BackColor = '#CCCC99'
$Button2.BackColor = '#CCCC99'
$Button3.BackColor = '#CCCC99'
etc...
I'm pretty sure there's a better and more efficient way to do this. Can anyone point me to the right direction?
I expect all buttons to look pretty much the same.
Thanks in advance.
You could loop through all of the buttons after they have been created and set their properties, like TheMadTechnician suggests…
But there is a better way. Think object-oriented programming. You have a Button class, and you want to change its default properties. In fact, you want all of your buttons to have those new properties. So really, what you want is a custom control that is like a button but slightly different.
Well, what do you know? There's a linguistic way to express that:
public class MyBeautifulButton : System.Windows.Forms.Button
{
public MyBeautifulButton()
{
// Set default properties here...
}
}
You can even go one fancier and override the specific properties, setting the appropriate attributes, to change their default values.
Then, instead of creating System.Windows.Forms.Button objects in your PowerShell code, you will create MyBeautifulButton objects.
Although I must say that I don't think the result will be terribly beautiful. The BackColor property of a button is one of those that I don't think should have ever been provided. Button controls are designed to be drawn using the system theme, which specifies the colors for you. It also allows the users to customize the colors as desired. Application-specified colors usually result in a visually jarring and downright ugly UI. Don't let your app stick out like a sore thumb. Buttons are utility controls. Consistency is key. Remember that GUI applications are not web pages.
Why not just apply that to all buttons after you add them to the form? Something along the lines of:
$MyForm.Controls | Where{$_.GetType().Name -eq "Button"} | ForEach{$_.BackColor = '#CCCC99'}
I'm getting started with Windows 8 App development using WinJS. I'm using the Light UI theme but I have set up a darker area on the left of the page (where the black back button is) and the issue is: you can't see the button.
I've trawled through the MSDN pages and the most I could find is how to style a button which doesn't actually explain how to change the colour of an actual asset.
http://msdn.microsoft.com/en-us/library/windows/apps/jj835822.aspx
I've also tried adding: win-ui-light and win-ui-dark classes to the button with no success.
I wondered if someone could point me in the right direction?
Many thanks for your time
Chris
First of all you have to delete the link tag that contain UI css by default and add it to document head , Dynamically.see below code :
var uistyle;
// call when your app load or resume.
function onappopen(){
uistyle = document.createElement('link');
uistyle.href = "//Microsoft.WinJS.2.0/css/ui-dark.css";
uistyle.rel = "stylesheet";
uistyle.id = "UIstyle";
document.head.appendChild(uistyle);}
// call when you want to change UI Style.
function UIstyle(UIbool){
if(UIbool=='light'){ uistyle.href = "//Microsoft.WinJS.2.0/css/ui-light.css";}
else {uistyle.href = "//Microsoft.WinJS.2.0/css/ui-dark.css";}}
Like: UIstyle('light'); for light UI in Windows 8 or "UIstyle()" for dark;
I used the DOM Explorer to find the buttons default values and overwrite them. It was the child element that needed to be overwritten: .win-back
I need to get a popup in the VisualTree which is a sibling of Application.Current.RootVisual. Is there a way to do this?
I couldn't find a way for this at the moment.
I have tried to get the parent of the RootVisual but it don't have such.
var frame = Application.Current.RootVisual as PhoneApplicationFrame;
FrameworkElement fi = (FrameworkElement)VisualTreeHelper.GetParent(frame);
Thanks in advance
That was wrong approach.
Here is the correct one and it works like a champ:
System.Collections.Generic.IEnumerable<Popup> popups = VisualTreeHelper.GetOpenPopups();
Popup popup = popups.ElementAt(0);
I want to some kind of option list when i hold a selection in a listbox. And i didn't find something default that does this, so i'm trying to build one of my own. So first is there such a feature in windows phone 7?
If not, then i need to open a combo box of listbox at the specified position where the selection event happened, i found out how to get the coordinates of the event as follows:
System.Windows.Point position = e.GetPosition(this);
double pX = position.X;
double pY = position.Y;
Howerver, i can't find a way to set the coordinates of the combobox for example in the view to those coordinates or so.
Help please
Perhaps what you want is a ContextMenu - there is one available in the Silverlight Toolkit for Windows Phone.
I want to create full screen topmost (screen saver) window with MFC? How to create such full screen window in MFC? I tried to create win32 application and i am able to create fullscreen top most window but i want to create using MFC so later i can put different MFC controls on that window?
Please help me.
Thanks,
Jim.
I think removing the border from the dialog resource and showing the window as maximized (ShowWindow(SW_SHOWMAXIMIZED)) should do the job.
As for topmost use the System Modal style in the dialog resource.
I do it with a Dialog Box app. In the resource editor properties for the dialog resource, set Border=None and Title Bar=False to eliminate all border elements. In OnInitDialog, use the following to resize the dialog to the entire desktop:
CRect rcDesktop;
rcDesktop.left = GetSystemMetrics(SM_XVIRTUALSCREEN);
rcDesktop.right = rcDesktop.left + GetSystemMetrics(SM_CXVIRTUALSCREEN);
rcDesktop.top = GetSystemMetrics(SM_YVIRTUALSCREEN);
rcDesktop.bottom = rcDesktop.top + GetSystemMetrics(SM_CYVIRTUALSCREEN);
MoveWindow(rcDesktop, FALSE);
This code works on multiple monitors, unlike maximizing the window.
No need to worry about making the window topmost, Windows will display it on a dedicated desktop with no other windows present.
You should be able to adapt the example code here to do what you want:
MSDN: Initializing a dialog box