vb.net if 30px away from screen border - vb.net

I have a resizable rectangle and also I have buttons that follow the bottom right side of it. But there is a problem, if the user re-sizes the box near the edge of the screen then the buttons will go off screen.
Although I've thought of a fix, and if the rectangle gets 32px close to the screens size then it moves the buttons [which will be above the line]. [Above the line is not the first option either].
I've tried using this code:
e.y, e.x = end of rectangle
If e.Y - 32 - = My.Computer.Screen.Bounds.Height Then
Label1.Text = "AboveLine"
Else
Label1.Text = "OutsideLine"
End If
At the moment I only want 'Label1.text' to change.. but it only works for that [32px] which is only 1px. Instead I want it to be like a boundary and if the rectangle size hits between 32px away from the edge of the screen and to the edge of the screen then it'll move the button by
Me.Button1.Location = New Point(e.X - 46, e.Y + 1)
Heres an example of what I mean
Image example
Hopefully someone can help. Thanks

I think this is what your after.
When the application is moved/dragged about, the 'Me.Move' event is fired
So what we are doing is checking the location of the right hand edge of the form, against the working area of the screen, the working area because that doesn't include the start bar, etc. And then the same with the bottom edge of the form
Private Sub Form1_Move(sender As Object, e As EventArgs) Handles Me.Move
If Me.Right > My.Computer.Screen.WorkingArea.Width - 32 Then
Label1.Text = "Too far right, move button"
End If
If Me.Bottom > My.Computer.Screen.WorkingArea.Height - 32 Then
Label1.Text = "Too far down, move button"
End If
End Sub
Use More than signs instaed of an '=', it works all the way to the edge and not just on the 32nd pixel

Related

Fill a Rectangular with an inflating Circle without crossing its borders (Ripple)

I have a control surface (my custom control) and a drawed rectangular smaller than the whole surface. Now I need to draw a circle (FillEllipse) within this rectangular and the circle must not overdraw the rectangular borders.
I made a ButtonStrip like this one know from Angular:
https://material.angular.io/components/button-toggle/overview
And want to create such ripples:
https://material.angular.io/components/ripple/examples
It is almost perfect. I would like to make such an animation. The filling progress is not a problem, but the fact, that I dont use kinda "child control buttons" in my ButtonStrip and therefore no "real" borders, I struggle with the not"over"drawing the borders of my clicked button.
And no, I will not use child buttons as controls to put into my strip. I dont want this control in control control. I am drawing the buttons and use the rectangulars as "address" for my events like Hover/Click/Clicked etc.
Here is an example of my ButtonStrip (Month is hovered). Day is clicked.
Every Button (in a List or Dictionary) has its own rectangular which is pre calculated:
Dim InnerWidth As Integer = If(_IOSwitchVisible = True,
(Me.Width - _IOSwitchWidth) \ Buttons.Count,
Me.Width \ Buttons.Count)
If InnerWidth = 0 Then Return
For Each b In Buttons.Values
b.Rect = New Rectangle(CurrLeft, 0, InnerWidth, Me.Height)
VerticalLinePos.Add(CurrLeft)
CurrLeft += InnerWidth
Next
This is only a part of the code.
And here is a snippet how I draw a clicked button (either hovered or not)
'Clicked
For Each btn In Buttons.Values.ToList.Where(Function(x) x.Clicked = True)
If _HoveredElement IsNot Nothing AndAlso _HoveredElement.Rect = btn.Rect Then
'If the button is already clicked
e.Graphics.FillRectangle(New SolidBrush(ClickedHoveredColor), btn.Rect)
Else
'Otherwise draw clicked color
e.Graphics.FillRectangle(New SolidBrush(ClickedColor), btn.Rect)
End If
Next
Does someone got an idea how to fill one of these buttons with a circle which must not overdraw to its neighbour buttons?
Edit: As soon as I (or you) found out how, I will include a loop to inflate the circle to animate a filling progress.
Thanks to Jimi I got it working with his Clip hint:
(The yellow circle is from ScreenToGif)
Private Sub AnimateRipple(G As Graphics, C As Color, R As Rectangle)
Dim ClipRegion As New Region(R)
G.SetClip(ClipRegion, Drawing2D.CombineMode.Replace)
Dim EllipseRect As Rectangle = R
EllipseRect.Width = 1
EllipseRect.Height = 1
EllipseRect.Y = R.Height \ 2
EllipseRect.X += R.Width \ 2
EllipseRect.Inflate(InflateValue, InflateValue)
Dim RippleBrush As SolidBrush = New SolidBrush(C)
G.FillEllipse(RippleBrush, EllipseRect)
G.ResetClip()
RippleBrush.Dispose()
End Sub

How to make VB.NET MDI parent full screen (without maximizing)?

I thought this would take 5 minutes. Spent 3 hours and haven't figured it out...
I have an MDI application and would like an easy way for the user to make it full screen without maximizing it, so I added a Windows/Full Screen menu option and put in this code to handle it:
Me.Left = 0
Me.Top = 0
Me.Width = Screen.PrimaryScreen.WorkingArea.Width
Me.Height = Screen.PrimaryScreen.WorkingArea.Height
The problem is this leaves gaps on the left, bottom, and right side. The top is the only screen edge that works as expected - snugged against the top. The others leave about a 1/8" gap to the screen edges, and 1/8" from the task bar at the bottom.
Sure, I could fudge it and hardcode +10 (or whatever) to the height and width, and -5 to the left. But that seems like a kludge (a fudge kludge), and maybe won't be the same for every monitor.
I tried the DPI awareness thing in the manifest, but it made no difference. I also tried Screen.PrimaryScreen.Bounds and Screen.PrimaryScreen.WorkingArea.X / Y, also with no joy.
It really shouldn't be this difficult. Wth?
Try this:
Dim diffW As Integer = Me.Width - Me.ClientSize.Width
Dim diffH As Integer = Me.Height - Me.ClientSize.Height
Me.ClientSize = New Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height - diffH)
Me.Location = New Point(-diffW / 2, 0)
I´m not quite sure if I understand you correct: You don´t like to have the user to press the maximize button? Instead you try to provide your own "maximize" function?
Ok, sounds strange, but anyway:
Did you already try this:
Screen.PrimaryScreen.WindowState = FormWindowState.Maximized
(sorry, copied from C# code if there is an syntax mayhem)
I understand it is late but this hack can solve:
for c#
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
for vb:
Me.FormBorderStyle = FormBorderStyle.None
Me.WindowState = FormWindowState.Maximized

VB.NET - Change form size by screen resolution:

I'm presuming the answers very simple, but here's the issue, my option menu has two parts, normal settings and advanced settings, the advanced settings are accessed by pressing the advance button, fairly basic. This will make the form bigger unveiling the further settings, but the only problem I have is making a form bigger on different resolution does not make it bigger by the same factor - to put what i saying into context, if i increase the size of my form on a standard 1080p monitor, then run my program on a laptop resolution of 1366 by 768, the form will be much smaller than what i got it to draw on the 1080p resolution screen.
Heres the code I'm using to increase the form size:
Private Sub Advance_btn_Click(sender As Object, e As EventArgs) Handles Advance_btn.Click
If advanced = 0 Then
Me.Size = New Drawing.Size(262, 198) ' will increase form size
Advance_btn.Text = "<" ' text for button changes to know i have pressed the button - (to '<')
advanced = 1
ElseIf advanced = 1 Then
Me.Size = New Size(262, 85) ' will decrease form size
Advance_btn.Text = ">" ' text for button changes to know i have pressed the button - (to '>')
advanced = 0
End If
End Sub
The form is also without borders, if that makes somewhat a difference, thanks.
Me.Height = Screen.PrimaryScreen.Bounds.Height
Me.Width = Screen.PrimaryScreen.Bounds.Width * 0.6
In this example I use for years, the width is set to 60% of the screen width. This is in an IF statement, where I check if the user has a 4K monitor, if not, a full-screen mode is set at application start-up. You can, perpahs, do a similar thing with your drawing area.

Resetting the position of the ball and the paddle when the player loses a life

I am designing a Breakout style game where you knock down bricks to earn points and complete the game. The game consists of a paddle, ball, and some bricks. I have implemented the changes in the ball direction when it bounces off the sides of the screen. So, when the ball touches the left and right sides, it will bounce back the other direction and when the ball touches the top side, it will bounce back the opposite direction. However, when the ball hits the bottom side, it should decrease the number of paddles left by 1 and, both the ball and paddle should appear in its original position (i.e. on the paddle). This is what I have coded for this:
'check bottom of screen
If PictureBox_ball.Top >= 403 Then
Timer_Main.Enabled = False
lbl_PaddlesLeft.Text = lbl_PaddlesLeft.Text - 1
PictureBox_ball.Location = New Point(321, 365)
PictureBox_paddle.Location = New Point(288, 383)
Timer_Main.Enabled = True
End If
when I run this code, it refuses to change the location of the paddle. It just stays where it is. Would this be affected by what I have coded for the movement of the paddle? This is what I have coded:
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If e.X > 0 And e.X < Me.Width - PictureBox_paddle.Width Then
PictureBox_paddle.Location = New Point(e.X, PictureBox_paddle.Top)
End If
End Sub
If the number of paddles is less than 0 (total paddles = 3) and the ball reaches the bottom of the screen then the game should display a message box saying "You Lost!". This is what I have coded for this:
'check number of paddles left and bottom of screen
If lbl_PaddlesLeft.Text < 0 And PictureBox_ball.Top >= 403 Then
Timer_Main.Enabled = False
MsgBox("You Lost!", MessageBoxButtons.RetryCancel)
End If
However, when I run this code, the message box does not display when the paddles is less than 0. All it does is the ball starts from the original position even though the paddles left is a negative number. How do I fix this?
Note: The first and third snippet of the code is in the Timer_Main_Tick event

VB.NET panel scrolling without showing scrollbars

I am trying to create a custom UI element: a panel, derived from the original panel, which is scrollable with special scrollbars (not the integrated ones) and has some other special abilities.
The actual problem is the scrolling. When I change the value of the custom scrollbar (e.g. scrolling), the panel-integrated scrollbars show up suddenly, although autoScroll = false.
Leading to the unintended state where both scrollbars are visible, the integrated and my custom one.
Private Sub ScrollB_EvValueChanged(NewVal As Integer) Handles ScrollB.EvValueChanged
Me.CleanPanel1.VerticalScroll.Value = NewVal
End Sub
How can I assign the new scrolling position (the new offset), determined by the custom scrollbar, to the panel without showing up panel-integrated scrollbars?
Sadly a panel (or usercontrol) with another panel on it and playing with the .Top and .Left properties of the inner panel to simulate scrolling is not an appropriate solution in my case.
Thank you for all your hints!
'I've been looking for methods of doing this all over, most of it is way more complicated than it needs to be, or you gotta write a whole dang program just to remove the bars to scroll. Anyhow, here's a quick, effective, neat method of doing this (since I was having trouble finding anything, I'll post it.
'e.delta detects a mouse wheel tick, if greater than 0, scroll up, less than 0 scroll down.
' the -91 part deducts some of the panel overhang (adjust as needed)
'I have buttons in this project that are 50 tall, so this scrolls perfectly for me.
'the nested if statements where there is no code (just else), tells the program to stop 'do nothing if a border is near by. The bottom of my panel, while scrolling, doesn't 'stop when the bottom of the panel (which is hanging off the bottom of the form quite 'some ways) reaches the bottom of the form, this can be adjusted by altering the 700 constant.
Private Sub DaddyPanel_MouseWheel(sender As Object, e As MouseEventArgs) Handles DaddyPanel.MouseWheel
If e.Delta < 0 Then
If (-DaddyPanel.Height - 91) > (DaddyPanel.Location.Y - 700) Then
Else
TextBox1.Text = DaddyPanel.Height & " " & DaddyPanel.Location.Y
DaddyPanel.Location = DaddyPanel.Location + New Point(0, -50)
End If
Else
If DaddyPanel.Location = New Point(0, 0) Then
Else
DaddyPanel.Location = DaddyPanel.Location + New Point(0, 50)
End If
End If
End Sub