refacc.blogg.se

Visual basic menustrip mnu
Visual basic menustrip mnu












  1. #VISUAL BASIC MENUSTRIP MNU HOW TO#
  2. #VISUAL BASIC MENUSTRIP MNU CODE#
  3. #VISUAL BASIC MENUSTRIP MNU WINDOWS#

'load saved file names from the Registry. Public Sub New(ByVal application_name As String, _ Add the following variables into it: Private m_ApplicationName As StringĪdd the rest of the class: Public Event OpenFile(ByVal file_name As String) This simply exits the application properly.Īdd a new class called MruList by clicking Project, Add Class. Private Sub Form1_FormClosing(ByVal sender As Object, _īyVal e As ) _ Private Sub mnuFileExit_Click(ByVal sender As System.Object, _īyVal e As System.EventArgs) Handles mnuFileExit.Click Here you just call the subs we created earlier from the associated menu item.Īdd the remaining events for the form: 'close the application Private Sub mnuFileOpen_Click_1(ByVal sender As System.Object, _īyVal e As System.EventArgs) Handles mnuFileOpen.Click Private Sub mnuFileSaveAs_Click(ByVal sender As System.Object, _īyVal e As System.EventArgs) Handles mnuFileSaveAs.Click Private Sub mnuFileSave_Click(ByVal sender As System.Object, _īyVal e As System.EventArgs) Handles mnuFileSave.Click

visual basic menustrip mnu

Private Sub m_MruList_OpenFile(ByVal file_name As String) _ If it is the first time you’ve worked with files in this way, I suggest you read up on the StreamReader and the StreamWriter objects.Īdd the following events: 'open a file selected from the MRU List I made use of a StreamReader object to read the content of the file into the Richtextbox, and I used a StreamWriter to save the content of the Rich textbox into a file. Whether you are saving or opening a file, almost the same happens. Stream_writer = New IO.StreamWriter(file_name) Private Sub SaveData(ByVal file_name As String) If Not (stream_reader Is Nothing) Then stream_reader.Close() MessageBoxButtons.OK, MessageBoxIcon.Error) MessageBox.Show("Error loading file" & file_name & _ Stream_reader = New IO.StreamReader(file_name)ĭim txt As String = stream_reader.ReadToEnd Private Sub LoadData(ByVal file_name As String) Now, add the LoadData and SaveData subs: 'load a data file It indicates that the file has not yet been saved if you are creating a new file. This fires when the content of the RichTextBox has changed. Private Sub rchFile_TextChanged(ByVal sender As System.Object, _īyVal e As System.EventArgs) Handles rchFile.TextChanged I will explain the class a bit later.Īdd the following sub procedure: 'mark the data as modified. I made reference to the MruList class here as well, because it needs to load the recent items when loaded. Inside Form_Load, you determine your application’s startup path. M_MruList = New MruList(APP_NAME, MenuStrip1, 4)

visual basic menustrip mnu

Init_dir.Substring(0, init_dir.Length - 4) If init_dir.EndsWith("\bin") Then init_dir = _ Private Sub Form1_Load(ByVal sender As System.Object, _īyVal e As System.EventArgs) Handles MyBase.Loadĭim init_dir As String = Application.StartupPath Now, add the Form_load event: 'Set the Dialog's initial directory. Notice how I keep setting the value of the DataDirty variable… Here I just made sure the content of the Rich Textbox has indeed changed, and depending on the displayed messagebox’s result, I either cancel, or save the information into a file. "Save Changes?", MessageBoxButtons.YesNoCancel) Select Case MessageBox.Show("The data has been modified. Add the DataSafe function now: 'Return true if it is safe to discard the current data. Here, I reference a function named DataSafe (which we will create now) and set up the Richtextbox and the rest of the screen. Private Sub mnuFileNew_Click(ByVal sender As System.Object, _īyVal e As System.EventArgs) Handles mnuFileNew.Click

#VISUAL BASIC MENUSTRIP MNU CODE#

mruList is a separate class for the Most Recently Used items I will explain this later.Īdd the following code for the New menu item: 'start a new document FileName will be the name of the file that gets used. Based on this, we will know that we need to save. Add the following variables to your form: Private Const APP_NAME As String = "Editor"Īpp_Name is my application’s name, DataDirty determines if the opened file’s content has changed. Let me start with the Form’s code, and then move to the other objects as we encounter them. Once done, design your form to resemble Figure 1:

#VISUAL BASIC MENUSTRIP MNU WINDOWS#

Start Visual Studio and create a new Windows Forms project. These file names appear in your file menu, an aid for quicker access. Basically, what you can expect is the functionality behind opening and saving files, as well as loading a most recently used list of files. You can ultimately save or open the file into or from the program itself. Our ProjectĪs you probably know, a text editor is a computer program with which you can enter text. We have a lot of work to do, so let’s get started.

#VISUAL BASIC MENUSTRIP MNU HOW TO#

Hello again! Today, I will show you how to make your own text editor in Visual Basic.














Visual basic menustrip mnu