How to get more than one parent control in form - vb.net

Newbie here :)
In order to achieve a transparency-type effect for pictureboxcharacter1 on the background, I have set pictureboxbackground1 as its parent.
this works fine.
For the second picturebox (on the same form) I tried the same thing and set pictureboxbackground2 as its parent so it would look transparent over pictureboxbackground2. However when I debug the application pictureboxcharacter2 disappears and only pictureboxbackground2 is visible.
the code I have is:
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.pictureboxcharacter1.Parent = Me.pictureboxbackground1
Me.pictureboxcharacter2.Parent = Me.pictureboxbackground2
End Sub
Really strange: if I put pictureboxcharacter2 on pictureboxbackground1 in the designer tab, while debugging it shows up on picturebackground2 and transparent (like how I wanted it to be)??
Does anyone know what's going on at all?
Please I'm NEED any help I could get

Is pictureboxcharacter1 and pictureboxcharacter2 one over other ? If so try making the one be other's parent.
Have a play with bring to front option and see if that works.

Related

Delete selected row in Datagridview

I have a datagridview in which I want to insert a button for removing the selected row. I created without any problems the AddRow Button and, following the same idea, I tried to create the RemoveRow button with the following code:
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
DataGridView2.Rows.Remove()
End Sub
When I start debugging I'm having BC30455 error, about not specified argument. What am I doing wrong? I tried to find out here in the forum but I've found only sth about C# and not VB.net
Best regards and thanks all are gonna answer me.

Why does my subroutine, which handles a double-click event on a listbox, not work?

I have declared a Sub that is meant to trigger when the listbox 'lstStudents' is double-clicked. However, it does not trigger when this happened. There can't be an error in the code itself as it is auto-generated. Why does the code not function as expected? The code is below:
Private Sub lstStudents_DoubleClick(sender As Object, e As EventArgs) Handles lstStudents.DoubleClick
Msgbox("test")
End Sub
The message box is only present for testing purposes.
Could You try to delete that previous "lstStudents" and add new one then apply the "ListBox1_DoubleClick" on it again to make sure it works.
Otherwise let us know what is going there because I think your code is normally and it should be working 100%.

Run VB.net app on second monitor

I'm a newbie at coding but I have done simple application for the plan I work for!!
I recently encounter a "little" issue with one of my application!
I build a Windows Form application, with multiple form, that run on a dual screen CNC. The CNC program have to run on the primary screen at a higher resolution. My application run on the second screen who is a touch screen at 1024;768.
The problem itself is if I run the code with the debug data everything run as I want, open the application on second screen and all the next form open on this screen. If I install it with the released data, all form open on the primary monitor, even if I drag them on second screen. After I closed them, they return on the primary.
Is there a way I can put a code line at the beginning of each form who make all form open on the secondary screen.
When the setup will work correctly I'll lock the screen setup just to be sure nobody will mess with the settings.
Please be gentle with me I don't have any formation on how to code. I learn from myself with reading on the web!!
Thanks all!!
Something like this should position the window at offset 100, 100 on the first non-primary screen found. You can adjust the location and/or size to suit your needs.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim secondaryMonitor = Screen.AllScreens.FirstOrDefault(Function(x) Not x.Primary)
If secondaryMonitor IsNot Nothing Then
Dim newLocation = secondaryMonitor.Bounds.Location
newLocation.Offset(100, 100) ' adjust as needed
Me.Location = newLocation
' Also see Me.Size and Me.Bounds
End If
End Sub
This worked for me:
Private Sub _MainForm_Move(sender As Object, e As EventArgs) Handles MyBase.Move
' preserve me.Location.x and me.Location.y here.
End Sub
Then, at program boot, restore: me.Location.x and me.Location.y

Weird functionality when using ScriptManager.RegisterStartupScript

I'm having this weird problem using the ScriptManager.RegisterStartupScript. Basically what I'm trying to accomplish when I click a button control, it goes back to the server, checks to see if any errors, and what I want to happen is that if there are any errors, want to use a popup box. The button control is inside an update panel. I thought the easiest way to accomplish this was to use a javascript alert box. So I finally got it working but when the alert box comes up it messes up my menu control until the alert box is going then its ok. Its kinda of hard to explain so I have insert a image to show you guys whats going on once the button is clicked. I dont know how to fix or whats going on, if someone could point me into the right direction. Also he my code im using.
Protected Sub btnPlan_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPlan.Click
'Dim sb As New System.Text.StringBuilder
sb.Append("<script language='javascript'>")
sb.Append("alert(' No data in the database ');")
sb.Append("</script>")
If (Not ClientScript.IsStartupScriptRegistered("JSScript")) Then
ScriptManager.RegisterStartupScript(UpdatePanel5, Me.GetType(), "JSScript", sb.toString(), True)
End If
You may try to use RegisterClientScriptBlock:
Protected Overrides Sub Page_Load(ByVal sender as Object, ByVal e As System.EventArgs)
MyBase.Page_Load(sender, e)
Try
If Not ScriptManager.IsInAsyncPostBack Then
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "AlertScript", "<script type='text/javascript' language='javascript'>function YourAlert(){alert(' No data in the database ');}</script>")
EndIf
Catch ex As Exception
End Try
End Sub
Thanks for all your suggestion. I skinned this a different way and got it to work the way I wanted. What i did was put the message in a hidden textbox and used jquery to ensure that the page was already load then alert the message if needed.

Focused row not working - Gridview

I am using Dev Express to develop a form in which i have a GridControl with a View inside a View.
It looks like this:
I am then trying to use the event ValidatingEditor to validate the user input.
I tried to do that by doing:
Private Sub grvObsAM_Artigos_ValidatingEditor(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles grvObsAM_Artigos.ValidatingEditor
Dim row As Integer = Me.grvObsAM_Artigos.FocusedRowHandle
This, however always returns me something like -99999..
I poked around and tried this other solution using the sender from the event:
Private Sub grvObsAM_Artigos_ValidatingEditor(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles grvObsAM_Artigos.ValidatingEditor
Dim grv As DevExpress.XtraGrid.Views.Grid.GridView = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
Dim row As Integer = grv.FocusedRowHandle
And using this second solution i managed to get the focused row handle. Even though this worked this time (because the event was triggered by the view itself and i had access to the sender) this doesn't solve my problem as there are other events where the sender is not the view and the problem persists.
Usign Me.grvObsAM_Artigos."insert anything here" doesn't seem to work properly.
Does anyone have any idea on why this is happening? Am i missing something?
Regards,
I think your issue is actually that you have several of the grvObsAM_Artigos gridviews. One for each row that has the details. So you need to use the view above ti to access the proper one. Using:
Dim grv as XtraGrid.Views.Grid.GridView = grvObsAM.GetDetailView(RowHandle, 0)
That should give you the right instance of the gridView you want. Everytime a master row is expanded and collapsed, the child is created and destroyed respectively.
This should give you a bit more background.
http://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsGridGridView_GetDetailViewtopic