This question already has an answer here:
How do you override the ContextMenu that appears when right clicking on winforms WebBrowser Control?
(1 answer)
Closed 6 years ago.
I'm using Axwebbrowser to display HTML page in my VB.NET application and i would like to know how disable its context menu ?
I use AxWebbrowser more than the original Webbrowser component because it handle the NewWindows 2 event that help me getting the popup url when a link is open in a new tab for example.
So i can't use the Webbrowser1.ContextMenuEnabled = False
Thanks for your answers
A simple method is to trap the WM_RBUTTONDOWN and WM_RBUTTONDBLCLK messages at the application level. You can add a message filter to your application using the statement Application.AddMessageFilter(instance of IMessageFilter). In the example below, the ImessageFilter interferace is implemented by the form containing the AXWebrowser control. As the filter is application wide, it is added/removed when the form activates/deactivates.
Public Class Form1
Implements IMessageFilter
Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
Const WM_RBUTTONDOWN As Int32 = &H204
Const WM_RBUTTONDBLCLK As Int32 = &H206
' check that the message is WM_RBUTTONDOWN Or WM_RBUTTONDBLCLK
' verify AxWebBrowser1 is not null
' verify the target is AxWebBrowser1
Return (m.Msg = WM_RBUTTONDOWN OrElse m.Msg = WM_RBUTTONDBLCLK) AndAlso (AxWebBrowser1 IsNot Nothing) AndAlso (AxWebBrowser1 Is Control.FromChildHandle(m.HWnd))
End Function
Protected Overrides Sub OnActivated(e As EventArgs)
MyBase.OnActivated(e)
' Filter is application wide, activate filter with form
Application.AddMessageFilter(Me)
End Sub
Protected Overrides Sub OnDeactivate(e As EventArgs)
MyBase.OnDeactivate(e)
' Filter is application wide, remove when form not active
Application.RemoveMessageFilter(Me)
End Sub
End Class
Related
I am creating a application to be used with a touch panel device. The touch panel device comes with a standard windows OSK (On screen Keyboard). Whilst testing its been concluded that the standard OSK is to large and too complex for what we need it in. So I have built my own OSK. some of the feilds though only requier numeric inputs so I though of futher simplifying the process by creating a new form which hosts a numeric pad. so far this is all working. the idea is then to have the app which ask for diffrent inputs then to trigger the OSK application, say that the user wants to enter a phonenumber in one textbox I then want to start the OSK app using a parameter that trigers the OSK to start the NumericForm form first... this too I have working but the thing I can't get right is to hide the AlphabetForm I have tried the following method but am a little stumpt on how to get this right
In short its the Me.hide which isnt working as expected?
Private Sub AlphabetForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
#Region "Recive startup parameters (if any)"
Try
Dim OSKParameters As String = Command()
If OSKParameters = "OSKNUM" Then
NumericForm.Show()
Me.Hide()
Else
ShiftSelect = 0
End If
Catch ex As Exception
'Do nothing
End Try
#End Region
End Sub
Three possible setups, as described in comments:
► Using the Application Framework, override OnStartup and set Application.MainForm to a Form object determined by a command-line argument:
To generate ApplicationEvents.vb, where Partial Friend Class MyApplication is found, open the Project properties, Application pane, click the View Application Events Button: it will add the ApplicationEvents.vb file to the Project if it's not already there.
Imports Microsoft.VisualBasic.ApplicationServices
Partial Friend Class MyApplication
'[...]
Protected Overrides Function OnStartup(e As StartupEventArgs) As Boolean
Application.MainForm = If(e.CommandLine.Any(
Function(cmd) cmd.Equals("OSKNUM")), CType(NumericForm, Form), AlphabetForm)
Return MyBase.OnStartup(e)
End Function
'[...]
End Class
► Disabling Application Framework, to start the Application from Sub Main().
In the Project->Properties->Application pane, deselect Enable application framework and select Sub Main() from the Startup form dropdown.
If Sub Main() doesn't exist yet, it can be added to a Module file. Here, the Module is named Program.vb.
Module Program
Public Sub Main(args As String())
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(True)
Dim startForm as Form = If(args.Any(
Function(arg) arg.Equals("OSKNUM")), CType(New NumericForm(), Form), New AlphabetForm())
Application.Run(startForm)
End Sub
End Module
► If the OSK can be moved to UserControls, similar to what jmcilhinney suggested, run the default container Form and select the UserControl to show using the same logic (inspecting the command-line arguments):
Public Class AlphabetForm
Public Sub New()
InitializeComponent()
Dim args = My.Application.CommandLineArgs
Dim uc = If(args.Any(
Function(arg) arg.Equals("OSKNUM")), CType(New NumericUC(), UserControl), New AlphabetUC())
Me.Controls.Add(uc)
uc.BringToFront()
uc.Dock = DockStyle.Fill
End Sub
End Class
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
first i work on visual studio 2008.
i have a form(frmOrdreEnCours) that call an another form(frmListe) on a button.click event .
frmListe has a ListBox where you can choose a thing and validate it,
But i was ask to add a button frmOrdreEnCours that do the exact same thing, but it had to choose a specific element and don't show the frmListe.
so i tried to simulate a click but it doesn't works without the .show() Method
and obviously my client don't want a to see a opened window even for a second.
Private Sub BtnVracSup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnVracSup.Click
Dim ArlTraduction As ArrayList = New ArrayList
ArlTraduction.Add(30163) 'Non-conformite operationnel - materiel
ArlTraduction.Add(30168) 'Non-conformite opérationnel - autres
Classes.Langues.Traduire(ArlTraduction)
Dim FrmListe As New FrmListe(FrmListe.TypeListe.OperationnelMaterielBacSupp, ArlTraduction(0).ToString, ArlTraduction(1).ToString, NumOrdre)
FrmListe.MdiParent = FrmParent
Dim HideIt As Boolean = False
FrmListe.Show() // i don't want this
FrmListe.Visible = HideIt // i even try this
FrmListe.BtnValider.PerformClick() // there's no .Click available
End Sub
PerformClick doesn't do anything, if target control's CanSelect is false.
And if control is not visible, CanSelect return false.
http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Button.cs,845bec419ca23629
You need call event handler (like BtnValider_Click) directry, but I think that looks bad code.
If you implemented like below:
Public Class FrmListe
Private Sub BtnValider_Click(sender As Object, e As EventArgs) Handles BtnValider.Click
' Validation codes '
End Sub
End Class
It's time to extract validation codes to another method.
Public Class FrmListe
Private Sub BtnValider_Click(sender As Object, e As EventArgs) Handles BtnValider.Click
IsValid()
End Sub
Public Function IsValid() As Boolean
' Validation codes '
Return True ' or Return False it is not valid '
End Function
End Class
and you can call this like following:
FrmListe.IsValid()
If you can, I recommend that you consider implement IsValid method in another class, like following:
Public Class ListeValidator
Public Function IsValid(type As FrmListe.TypeListe, traduction1 As String, traduction2 As String, numOrdre As Object)
' I dont know type of NumOrdre '
' validation code here '
End Function
End Class
I hope this helps you.
I am creating a browser using Cefsharp in VB.Net, and I have been trying to create a download window that shows the progress of the current download. I don't know if I am doing something wrong or if it is the way CEF works, but I put in a download handler by adding browser.DownloadHandler = New DownloadHandler to Form1_Load and creating a new class like this (with downloading being the form I created for showing the progress):
Public Class DownloadHandler
Implements IDownloadHandler
Public Function OnBeforeDownload(downloadItem As DownloadItem, ByRef downloadPath As String, ByRef showDialog As Boolean) As Boolean Implements IDownloadHandler.OnBeforeDownload
downloadPath = downloadItem.SuggestedFileName
showDialog = True
downloading.Show()
Return True
End Function
Public Function OnDownloadUpdated1(downloadItem As DownloadItem) As Boolean Implements IDownloadHandler.OnDownloadUpdated
My.Settings.downloadpercent = downloadItem.PercentComplete.ToString
Return False
End Function
End Class
On the downloading form I have this code for showing the progress:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim percentcomplete As Integer = My.Settings.downloadpercent * 5
Me.PictureBox1.Size = New Size(percentcomplete, 25)
End Sub
Private Sub downloading_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
This may not be the best way to show a ProgressBar, but I have a picture box that just has a green bar, and the total width of the form is 500px. The code is telling it to read the PercentComplete setting put in My.Settings.downloadpercent, multiply it by 5, so when the progress in 100%, it will go across the whole form.
The problem is that the ProgressBar is not being updated to show the current progress. It goes a little bit, but then it just stops. Am I doing something wrong, or is OnDownloadUpdated not a good place to put that? Any suggestions of how to fix this?
Edit:
I am using CefSharp 39.0.0-pre03. Also, when the save file dialog comes up, no matter if you click Save or Cancel, the browser always triggers a LoadError, so it loads the custom HTML error page I made, and since it requires a URL for loading HTML, I put in "http://rendering/"... So I guess that would be a domain change. That issue (in the comments) could be the problem, but then we also need to figure out why it is triggering a LoadError.
A simple solution that may be of interest to those who faced the same or similar problem:
Declare Public your Picturebox, in a module:
Module Module1
Public PictureBox1 As New PictureBox
End Module
In MainForm you can declare the attributes you want (after the InitializeComponent). Example:
With PictureBox1
.BorderStyle = Border3DStyle.Flat
.Image = Bitmap.FromFile(YourImageFileName)
'......
End With
In the DownloadHandler Class:
Public Function OnDownloadUpdated1(downloadItem As DownloadItem) As Boolean
Implements IDownloadHandler.OnDownloadUpdated
Dim percentcomplete As Integer=downloadItem.PercentComplete * 5
PictureBox1.Size = New Size(percentcomplete, 25)
Return False
End Function
This question already has answers here:
Visually remove/disable close button from title bar .NET
(13 answers)
Closed 8 years ago.
my problem is so simple but I can't seem to get it solved.
I just want to remove the Close Button from my form and don't remove the icon.
I used ControlBox = false but it removes the form's icon as well, I just want to keep it.
Is there anyway I can do it either by code or properties?
Add it under Public Class Form ... :
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim Param As CreateParams = MyBase.CreateParams
Param.ClassStyle = Param.ClassStyle Or &H200
Return Param
End Get
End Property
It should work perfectly!
If you want something full of capabilities, then you could use my SystemMenuManager By Elektro Class.
Just add all the code into a single Class and use it like in the example below:
Public Class Form1
Dim SystemMenu As New SystemMenuManager(Me)
Private Shadows Sub Load() Handles MyBase.Load
' Disables the 'Close' button and 'Close' menu-item.
SystemMenu.SetItemState(SystemMenuManager.Item.Close,
SystemMenuManager.ItemState.Disabled)
End Sub
End Class
I'm trying to build a Text Adventure game in VB.net, just like the days of old. The obvious choice would be a Console application, however, I have decided on a Windows Form because I am hoping to include interactive buttons and pictures. Currently, I have already got on my form a picture box and a Rich Text Box. I was hoping that with the Rich Text Box I could achieve something that worked in the same way as a console. Alas, my efforts are futile. Everything I have tried has failed, including: reading Rich_Text_Box.Text and Rich_Text_Box_KeyUp with an if statement for enter being pressed to call the procedure for an enter button.
I was wondering if there was any way to include a Console with standard Console.WriteLine and Console.ReadLine capabilities inside of my Form? This would very much shorten my task and streamline the whole process.
Any ideas?
You could use not one but two Textboxes for your purpose. tbOutput and tbInput. tbOutput would be Multiline and ReadOnly whereas tbInput would be single line, not readonly and placed beneath tbOutput. Then to process inputs you could do something like:
Private Sub Output(s As String)
If s <> "" Then
tbOutput.AppendText(vbCrLf & ">> " & s)
End If
End Sub
Private Sub tbInput_KeyDown(sender As Object, e As KeyEventArgs) Handles tbInput.KeyDown
If e.KeyCode = Keys.Enter Then
If tbInput.Text <> "" Then
Output(tbInput.Text)
' Handle input value
tbInput.Text = ""
End If
End If
End Sub
At the 'Handle input value you would check the user input and handle it according to your needs. Use Lucida Console font in bold in gray and black background for style :-)
Sure, a RichTextBox can be used to emulate a console. Some surgery is required to avoid the user from making it malfunction as a console. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form. Subscribe the InputChanged event to detect when the user presses the Enter key, the Input property gives you the typed text. Use the Write() or WriteLine() methods to add text.
Imports System.Windows.Forms
Public Class RichConsole
Inherits RichTextBox
Public Event InputChanged As EventHandler
Public ReadOnly Property Input() As String
Get
Return Me.Text.Substring(InputStart).Replace(vbLf, "")
End Get
End Property
Public Sub Write(txt As String)
Me.AppendText(txt)
InputStart = Me.SelectionStart
End Sub
Public Sub WriteLine(txt As String)
Write(txt & vbLf)
End Sub
Private InputStart As Integer
Protected Overrides Function ProcessCmdKey(ByRef m As Message, keyData As Keys) As Boolean
'' Defeat backspace
If (keyData = Keys.Back OrElse keyData = Keys.Left) AndAlso InputStart = Me.SelectionStart Then Return True
'' Defeat up/down cursor keys
If keyData = Keys.Up OrElse keyData = Keys.Down Then Return True
'' Detect Enter key
If keyData = Keys.[Return] Then
Me.AppendText(vbLf)
RaiseEvent InputChanged(Me, EventArgs.Empty)
InputStart = Me.SelectionStart
Return True
End If
Return MyBase.ProcessCmdKey(m, keyData)
End Function
Protected Overrides Sub WndProc(ByRef m As Message)
'' Defeat the mouse
If m.Msg >= &H200 AndAlso m.Msg <= &H209 Then Return
MyBase.WndProc(m)
End Sub
End Class