I'm trying to make a program where there are multiple forms. Now what I would like to accomplish is that, whenever I open another form, the current form will close but I would like to do that without the forms having to vanish with an effect. Is there a way in the properties to do that? I tried changing the DoublBuffered into TRUE but it has no effect (I mean, the effect was still there). Can somebody point me to the right direction please? Thanks in advance. :D
By the way, I'm using:
Form2.Show()
Me.Close()
I haven't tried it out, but you can use the following. Assuming you have 2 Forms(1,2)
private void Form1_Load(Object sender, EventLog e)
{
if((bool)Form1.ActiveForm)
{
Form1.Visible = true;
Form2.Visible = false;
// Rest of your code to display
}
if((bool)Form2.ActiveForm)
{
Form1.Visible = false;
Form2.Visible = true;
// Rest of your code to display
}
}
Use this,
Form1.Opacity = 0
Here are places to add it. First set Form 2 opacity as 0 in visual studio. and then go to the form load and after loading all the things you need put in,
Form2.Opacity = 100
Then before form 1 closing put in,
Me.Opacity = 0
You just need to know where to set to 0 and where to 100. It will work good. But I am not sure why you don't want that effect.
Related
My ContentDialog is styled like a login form. It verifies password via connection thru SQLite. So in the Primary button's auto-generated Click event I have something like below (I made it Async btw):
Dim deferral As ContentDialogButtonClickDeferral = args.GetDeferral
If Await conn.Table(Of UserAccount).Where(Function(a) a.Username = UsernameTextBox.Text).CountAsync = 0 Then
args.Cancel = True
Dim x As New Windows.UI.Popups.MessageDialog("Username does not exist!")
Await x.ShowAsync
Else
'Other conditions
End If
deferral.Complete()
Some researching got me to think the Deferral is needed for Async situations (to no avail). Currently, with the above code I am getting a Reflection.TargetInvocationException on the Await line.
What I want to achieve is display a MessageDialog if username does not exist; the ContentDialog remaining onscreen for the user to correct himself.
Thanks!
Replace the "UsernameTextBox.Text" with a hardcoded value and it should work.
Maybe bind the textbox with a TwoWay mode into a variable and then use that variable in that statement.
I'm trying to elaborate if the complete form is visible on screen. To clarify this: I don't care if the form is partially or fully hidden by another form, I just want to know, if the form is completely on the screen.
In Windows it is possible to move forms around, such that they are hidden half way. That is because you can move them past the actual bounds of any monitor. (Further to the left, right or bottom.) How can I check if that is the case in an easy way?
What I figured I could do is to check if the form is in bounds of SystemInformation.VirtualScreen. The problem here is, that not every pixel of the virtual screen is actually visible. Of course this would work if SystemInformation.MonitorCount = 1
Still I'm not really happy with this.
Public Function IsOnScreen(ByVal form As Form) As Boolean
Dim screens() As Screen = Screen.AllScreens
For Each scrn As Screen In screens
Dim formRectangle As Rectangle = New Rectangle(form.Left, form.Top, form.Width, form.Height)
If scrn.WorkingArea.Contains(formRectangle) Then
Return True
End If
Next
Return False
End Function
Best way I can think of is that you check that all four corners of the form are on a screen. Like this:
public bool FormOnScreen(Form frm) {
if (frm.IsHandleCreated) throw new InvalidOperationException();
if (!frm.Visible || frm.WindowState == FormWindowState.Minimized) return false;
return PointVisible(new Point(frm.Left, frm.Top)) &&
PointVisible(new Point(frm.Right, frm.Top)) &&
PointVisible(new Point(frm.Right, frm.Bottom)) &&
PointVisible(new Point(frm.Left, frm.Bottom));
}
private static bool PointVisible(Point p) {
var scr = Screen.FromPoint(p);
return scr.Bounds.Contains(p);
}
Working on a Metro style app in C#. I have a custom control which inherits from Grid. MyGrid contains some other custom controls. I'm trying to do hit testing on those controls in the PointerReleased handler:
void MyGrid_PointerReleased(object sender, PointerRoutedEventArgs e)
{
PointerPoint pt = e.GetCurrentPoint(this);
var hits = VisualTreeHelper.FindElementsInHostCoordinates(pt.Position, this);
int breakhere = hits.Count();
}
After this code executes, hitCount is 0. If I move the PointerReleased handler one control higher in the visual tree heirarchy then hitCount is correct the first time and 0 after that. I set up a test project with similar XAML layout to try to reproduce the problem and it works correctly every time. So I'm not sure what bad thing I have done that is preventing VisualTreeHelper from working. I'm not really sure how to proceed debugging this. Any ideas what would cause this function to return no results?
I make two methodes like this:
private void Next(string argument)
{
Current = Clients[Clients.IndexOf(Current) + 1];
((DelegateCommand)NextCommand).RaiseCanExecuteChanged();
}
private void Previous(string argument)
{
Current = Clients[Clients.IndexOf(Current) - 1];
((DelegateCommand)PreviousCommand).RaiseCanExecuteChanged();
}
and bind to the xaml:
Every thing work fine. And the next button becomes inactive/grey out when it hits the last post.
The problem is it (the Next button) still inactive when I click the Previous button. The Next button becomes inactive all the time.
My question is how I could make the Next button active again? Thank for all help.
I assume you are talking about a WPF Application.
There are several reasons your button could become / stay inactive:
Your CanExecute implementation is faulty and returns false even if it should return true
You didnt implement CanExecute or didnt hook it up correctly
The CommandManager didn't realize it's time to requery the commands
You've got a problem with the Focus on your Window / Control
You need to show more of the code so it gives us a broader picture of what you are trying to do.
Say I have 3 forms , Form A , Form B , Form C.
I want Form B to be on top of Form A
and Form C to be on top of Form B.
how do I accomplish this ?
When you call ShowDialog pass the form that you want it to be in front of as a parameter to ShowDialog.
Use the Show(owner) overload to get form B on top of A. You'll need to set the size and location in the Load event so you can be sure it is exactly the right size even after scaling. And listen for the LocationChanged event so you can move the bottom form as well. This works well, other than a few interesting minimizing effects on Win7.
private void button1_Click(object sender, EventArgs e) {
var frmB = new Form2();
frmB.StartPosition = FormStartPosition.Manual;
frmB.Load += delegate {
frmB.Location = this.Location;
frmB.Size = this.Size;
};
frmB.LocationChanged += delegate {
this.Location = frmB.Location;
};
frmB.Show(this);
}