主頁 > 後端開發 > 在子表單中發送資料

在子表單中發送資料

2021-10-28 04:54:54 後端開發

我有 3 個表單,分別是 MainForm、Form1 和 Form2。MainForm 在Panel. 在單擊buttonMainForm 中的a時,我正在使用ShowDialog()方法打開 Form2 現在我有一個treeviewin Form2. 現在我想將在 Form2 中選擇的節點傳遞回comboboxForm1 中的 a如何做到這一點?Form1.Activate()在 Form2 中嘗試過,但代碼沒有Activate在 Form1 中命中方法。

我也在使用,Form1.ComboBox1.Items.Add(Me.TreeView1.SelectedNode.Text)但一旦 Form2 關閉,我就看不到 ComboBox 中的任何專案。我在這里缺少什么?

下面是代碼以便更好地理解。

MainForm

public Class MainForm

   private Sub OpenChildForm(childForm As Form)
       panelFormContainer.Controls.Add(childForm)
       childForm.Dock = DockStyle.Fill
       childForm.Show()
   End Sub  
   
   private sub MainForm_OnLoad(sender As Object, e as EventArgs) Handles Me.Load
      
      'Adding child form to a Panel in Main Form
      OpenChildForm(new Form1())
   End Sub

   'Open Form 2 on Button Click
   private sub btnOpenForm3_Click(sender As Object, e as EventArgs) Handles btnOpenForm3.Click
       Form2.ShowDialog()
   End Sub 
End Class   

Form2 - Child Form Opened by button click in MainForm

Public Class Form2

   'Click back button to go back to Main Form which is already having Form1 as child
   Private Sub btnBack_Click(sender As Object, e As EventArgs)
      Me.Close()
      Form1.Activate()
   End Sub

   'Click a Button to Add Selected Treeview node to Combo in Form1 
   Private Sub btnAdd_Click(sender As Object, e As EventArgs) btnAdd.Click
      Form1.ComboBox1.Items.Add(Me.TreeView1.SelectedNode.Text)
   End Sub

End Class

更新:我已經更新了代碼,但仍然沒有在 Child Form1 的 ComboBox 中得到任何東西

MainForm

Public Class Form1

Private currentChildForm As Form = Nothing
Private ownerForm As Form = Nothing
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    OpenChildForm(New ChildForm1())

End Sub

Private Sub OpenChildForm(childForm As Form)
    If currentChildForm IsNot Nothing Then
        currentChildForm.Close()
    End If

    childForm.TopLevel = False
    childForm.FormBorderStyle = FormBorderStyle.None
    panelFormContainer.Controls.Clear()

    panelFormContainer.Controls.Add(childForm)

    childForm.Dock = DockStyle.Fill

    childForm.BringToFront()
    childForm.Show()

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim dialogForm As ChildForm2 = New ChildForm2()
    '
    Dim result = dialogForm.ShowDialog()
    If result = DialogResult.OK Then
        AddHandler ChildForm2.Button1.Click, AddressOf ChildForm1.objForm2_Passvalue
    End If
End Sub


End Class

ChildForm1 which is hosted in MainForm

Public Class ChildForm1
    Private Sub ChildForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    If ComboBox1.Items.Count > 0 Then
        ComboBox1.SelectedIndex = 0
    End If
End Sub

Private Sub ChildForm1_Activated(sender As Object, e As EventArgs) Handles Me.Activated

End Sub

Public Sub objForm2_Passvalue(sender As Object, e As EventArgs)
    Me.ComboBox1.Items.Add(PageDetail.PageTitle)
End Sub

End Class

ChildForm2 -- Which is opened as Dialog

Public Class ChildForm2

Private Sub ChildForm2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    TreeView1.ExpandAll()
    Button1.DialogResult = DialogResult.OK
End Sub

Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    PageDetail.PageTitle = TreeView1.SelectedNode.Text
    Me.Close()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Me.Close()
End Sub
End Class

PageDetail: Class used to get and set data

Public NotInheritable Class PageDetail

    Private Shared pageTitleValue As String

    Public Shared Property PageTitle As String
        Get
            Return pageTitleValue
        End Get
        Set(value As String)
            pageTitleValue = value
        End Set
    End Property

End Class

在子表單中發送資料

uj5u.com熱心網友回復:

與其將 aForm放在面板上,不如考慮創建 aUserControl并將其放置在面板上。下面顯示了如何將資料從顯示的 Form (Form2) 傳遞ShowDialog()到存在于不同表單 (MainForm) 上的 UserControl (UserControl1)。

MainForm是啟動形式。如果需要,可以將 UserControl 替換為 Form。

創建一個新專案

VS 2019

  • 在 VS 選單中,單擊檔案

  • 選擇新建

  • 選擇專案

  • 在子表單中發送資料

  • 選擇Windows 表單應用程式 (.NET Framework)

    在子表單中發送資料

  • 單擊下一步

  • 輸入所需的專案名稱

  • 點擊創建


打開解決方案資源管理器

  • 在 VS 選單中,選擇查看
  • 選擇解決方案資源管理器

添加用戶控制元件(名稱:UserControl1.vb)

  • 在解決方案資源管理器中,右鍵單擊 <專案名稱>,選擇添加

  • 選擇用戶控制元件(Windows 表單)...(名稱:UserControl1.vb)

  • 添加一個Label(文本:“選擇一個”)

  • 添加一個ComboBox(名稱:ComboBox1)

    在子表單中發送資料

用戶控制元件1.vb

Public Class UserControl1

    Private Sub UserControl1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Public Sub PopulateComboBox(value As String)
        'remove existing data from ComboBox
        ComboBox1.Items.Clear()
        ComboBox1.Text = String.Empty

        'add 
        ComboBox1.Items.Add(value)

        If ComboBox1.Items.Count = 1 Then
            'if only 1 item exists, select it
            ComboBox1.SelectedIndex = 0
        End If
    End Sub
End Class

注意:如果使用 aForm而不是 a UserControl,請將 for 代碼添加PopulateComboBox到您的表單中。


添加表單(名稱:Form2.vb)

  • 在解決方案資源管理器中,右鍵單擊 <專案名稱>,選擇添加

  • 選擇表單(Windows 表單)...(名稱:Form2.vb)

  • 添加標簽

  • 添加一個TreeView(名稱:TreeView1)

  • 添加按鈕(名稱:btnAdd;文本:添加)

  • Double-click "btnAdd" to add the Click event handler

  • Add a Button (Name: btnCancel; Text: Cancel)

  • Double-click "btnCancel" to add the Click event handler

    在子表單中發送資料

In Solution Explorer, right click Form2.vb, and select View Code

Form2.vb

Imports System.IO
Public Class Form2

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        PopulateTreeView()
    End Sub

    'ToDo: Replace this function with one that returns the desired data
    Public Function GetSelectedValue() As String
        Return TreeView1.SelectedNode.Text
    End Function

    Private Sub PopulateTreeView()

        'ToDo: Replace this code with your desired code to populate the TreeView

        'clear
        TreeView1.Nodes.Clear()

        Dim topNode As TreeNode = New TreeNode("Computer")

        TreeView1.Nodes.Add(topNode)

        Dim logicalDrives As String() = Directory.GetLogicalDrives()

        If logicalDrives IsNot Nothing Then
            For Each drive As String In logicalDrives
                Debug.WriteLine("drive: " & drive.ToString())

                Try
                    Dim dirInfo As DirectoryInfo = New DirectoryInfo(drive)

                    TreeView1.Nodes.Add(New TreeNode(drive))

                Catch ex As Exception
                    'do nothing
                End Try
            Next
        End If
    End Sub

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        'in MainForm we'll subscribe to the Add button Click event and retrieve the data by calling function "GetSelectedValue", so all we have to do here is close the form
        Me.Close()
    End Sub

    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
End Class

Rename Form1 to MainForm

  • In Solution Explorer, right-click Form1.vb
  • Select Rename
  • Enter MainForm.vb
  • When prompted "You are renaming a file. Would you also like to perform a rename in this project of all references to the code element 'Form1'? Click Yes
  • In Properties Window, for "MainForm", set Text = "MainForm"

Build Project

  • In Solution Explorer, right-click <project name>, select Build

MainForm

  • Add a panel to MainForm (Name: panel1)

  • In Toolbox (View => Toolbox), expand: <solution name> Components

  • Drag UserControl1 onto panel1 on MainForm

  • Add Button (Name: btnOpenForm2; Text: Open Form2)

  • Double-click "btnOpenForm2" to add the Click event handler

    在子表單中發送資料

In Solution Explorer, right click MainForm.vb, and select View Code

MainForm.vb

Public Class MainForm

    Private frm2 As Form2 = Nothing

    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnOpenForm2_Click(sender As Object, e As EventArgs) Handles btnOpenForm2.Click
        If frm2 Is Nothing Then
            'create new instance
            frm2 = New Form2()
        End If

        'subscribe to events (add event handlers)
        AddHandler frm2.btnAdd.Click, AddressOf Frm2BtnAdd_Click

        'show dialog 
        frm2.ShowDialog()

        'the code below will execute after frm2 is closed

        'unsubscribe from events (remove event handlers)
        RemoveHandler frm2.btnAdd.Click, AddressOf Frm2BtnAdd_Click

        'dispose
        frm2.Dispose()

        frm2 = Nothing
    End Sub

    Private Sub Frm2BtnAdd_Click(sender As Object, e As System.EventArgs)

        'call method to populate ComboBox
        'UserControl11.PopulateComboBox(frm2.GetSelectedValue())

        'call function to get data
        Dim userSelection As String = frm2.GetSelectedValue()

        'call method to populate ComboBox
        UserControl11.PopulateComboBox(userSelection)

    End Sub
End Class

Here's a demonstration:

在子表單中發送資料

Resources

  • 在子表單中發送資料

    MainForm為啟動表單,是父母雙方ChildForm1ChildForm2(即:兩個實體ChildForm1,并ChildForm2在創建的MainForm)

    創建一個新專案

    VS 2019

    • 在 VS 選單中,單擊檔案
    • 選擇新建
    • 選擇專案
    • 在子表單中發送資料
    • 選擇Windows 表單應用程式 (.NET Framework)

    在子表單中發送資料

    • 單擊下一步
    • 輸入所需的專案名稱
    • 點擊創建

    打開解決方案資源管理器

    • 在 VS 選單中,選擇查看
    • 選擇解決方案資源管理器

    添加表單(名稱:ChildForm1.vb)

    • 在解決方案資源管理器中,右鍵單擊 <專案名稱>,選擇添加
    • 選擇表單(Windows 表單)...(名稱:ChildForm1.vb)
    • 添加一個Label(文本:“選擇一個”)
    • 添加一個ComboBox(名稱:ComboBox1)

    在子表單中發送資料

    在解決方案資源管理器中,右鍵單擊ChildForm1.vb,然后選擇查看代碼

    子表單1.vb

    Public Class ChildForm1
    
        Public WriteOnly Property PageTitle As String
            Set(value As String)
                'populate ComboBox
                PopulateComboBox(value)
            End Set
        End Property
    
        Sub New()
    
            ' This call is required by the designer.
            InitializeComponent()
    
            ' Add any initialization after the InitializeComponent() call.
    
        End Sub
    
        Sub New(pageTitle As String)
    
            ' This call is required by the designer.
            InitializeComponent()
    
            ' Add any initialization after the InitializeComponent() call.
            PopulateComboBox(pageTitle)
    
        End Sub
    
        Sub New(pageTitles As List(Of String))
    
            ' This call is required by the designer.
            InitializeComponent()
    
            ' Add any initialization after the InitializeComponent() call.
            PopulateComboBox(pageTitles)
    
        End Sub
    
        Private Sub ChildForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Public Sub PopulateComboBox(pageTitle As String)
            'create new instance
            Dim pageTitles As New List(Of String)
    
            'add
            pageTitles.Add(pageTitle)
    
            'populate ComboBox
            PopulateComboBox(pageTitles)
        End Sub
    
        Public Sub PopulateComboBox(pageTitles As List(Of String))
            'remove existing data from ComboBox
            ComboBox1.Items.Clear()
            ComboBox1.Text = String.Empty
    
            For Each pTitle In pageTitles
                'add 
                ComboBox1.Items.Add(pTitle)
            Next
    
            If ComboBox1.Items.Count = 1 Then
                'if only 1 item exists, select it
                ComboBox1.SelectedIndex = 0
            End If
        End Sub
    End Class
    

    添加表單(名稱:ChildForm2.vb)

    • 在解決方案資源管理器中,右鍵單擊 <專案名稱>,選擇添加
    • Select Form (Windows Forms)... (Name: ChildForm2.vb)
    • Add a Label
    • Add a TreeView (name: TreeView1)
    • Add a Button (Name: btnAdd; Text: Add)
    • Double-click "btnAdd" to add the Click event handler
    • Add a Button (Name: btnCancel; Text: Cancel)
    • Double-click "btnCancel" to add the Click event handler

    在子表單中發送資料

    In Solution Explorer, right click ChildForm2.vb, and select View Code

    ChildForm2.vb

    Public Delegate Sub PassValueHandler(ByVal strValue As String)
    
    Public Class ChildForm2
    
        Public Event PassValue As PassValueHandler
    
        Public ReadOnly Property PageTitle
            Get
                Return TreeView1.SelectedNode.Text
            End Get
        End Property
    
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            PopulateTreeView()
            TreeView1.ExpandAll()
        End Sub
    
        Public Function GetPageTitle() As String
            Return PageTitle
        End Function
    
        Private Sub PopulateTreeView()
            'ToDo: Replace this method with code to populate your TreeView
    
            TreeView1.Nodes.Clear()
    
            'Parent 1
            Dim node1 As TreeNode = New TreeNode("Parent 1")
            Dim childNode1 As TreeNode = New TreeNode("Child Node 1")
    
            'add 
            node1.Nodes.Add(childNode1)
    
            'add 
            TreeView1.Nodes.Add(node1)
    
            'Parent 2
            Dim node2 As TreeNode = New TreeNode("Parent 2")
            Dim childNode2 As TreeNode = New TreeNode("Child Node 2")
    
            'add 
            node2.Nodes.Add(childNode2)
    
            'add 
            TreeView1.Nodes.Add(node2)
    
        End Sub
    
        Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
            'raise event
            RaiseEvent PassValue(TreeView1.SelectedNode.Text)
    
            'set value
            Me.DialogResult = DialogResult.OK
    
            'close
            Me.Close()
    
        End Sub
    
        Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
            'set value
            Me.DialogResult = DialogResult.Cancel
    
            'close
            Me.Close()
        End Sub
    End Class
    

    Rename Form1 to MainForm

    • In Solution Explorer, right-click Form1.vb
    • Select Rename
    • Enter MainForm.vb
    • When prompted "You are renaming a file. Would you also like to perform a rename in this project of all references to the code element 'Form1'? Click Yes
    • In Properties Window, for "MainForm", set Text = "MainForm"

    MainForm

    • Add a panel to MainForm (Name: panelFormContainer)
    • Add Button (Name: btnOpenChildForm2; Text: Open ChildForm2)
    • Double-click "btnOpenChildForm2" to add the Click event handler

    在子表單中發送資料

    In Solution Explorer, right click MainForm.vb, and select View Code

    In the code below, I've written it in such a way that it allows one to choose different options for both retrieving data from a child form, as well as, multiple options for sending data to a child form.

    MainForm.vb

    Public Class MainForm
    
        Private dialogForm As ChildForm2 = Nothing
        Private currentChildForm As Form = Nothing
        Private ownerForm As Form = Nothing
    
        Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            'open Form
            OpenChildForm(New ChildForm1())
        End Sub
    
        Private Sub OpenChildForm(ByRef childForm As Form)
            If currentChildForm IsNot Nothing Then
                currentChildForm.Dispose()
                currentChildForm = Nothing
            End If
    
            'set value
            currentChildForm = childForm
    
            'set properties
            childForm.Dock = DockStyle.Fill
            childForm.TopLevel = False
            childForm.FormBorderStyle = FormBorderStyle.None
    
            'remove existing controls
            panelFormContainer.Controls.Clear()
    
            'add
            panelFormContainer.Controls.Add(childForm)
    
            'show
            childForm.Show()
    
        End Sub
    
        Private Sub PopulateChildForm1ComboBox(pageTitle As String)
            If currentChildForm.GetType() = ChildForm1.GetType() Then
                'currentChildForm is an instance of ChildForm1
    
                'create reference
                Dim frm = CType(currentChildForm, ChildForm1)
    
                'option 1 - populate ComboBox by calling method
                frm.PopulateComboBox(pageTitle)
    
                'option 2 - populate ComboBox by setting property
                'frm.PageTitle = PageDetail.PageTitle
            End If
        End Sub
    
        Private Sub btnOpenChildForm2_Click(sender As Object, e As EventArgs) Handles btnOpenChildForm2.Click
            'ToDo: Replace this method with code from Option 1, Option 2, or Option 3 below
                               ...
    
        End Sub
    
        Private Sub DialogForm_BtnAdd_Click(sender As Object, e As System.EventArgs)
    
            'option 1 - get page title from property
            PageDetail.PageTitle = dialogForm.PageTitle
    
            'option 2 - get page title by calling function
            'PageDetail.PageTitle = dialogForm.GetPageTitle()
    
            'populate ComboBox
            PopulateChildForm1ComboBox(PageDetail.PageTitle)
        End Sub
    
        Private Sub DialogForm_PassValue(e As String)
            'set value
            PageDetail.PageTitle = e
    
            'populate ComboBox
            PopulateChildForm1ComboBox(e)
        End Sub
    End Class
    

    Choose one of the following options for retrieving data from ChildForm2. Replace the method btnOpenChildForm2_Click (in MainForm.vb) with the code listed below.

    Option 1 (DialogResult.OK)

    Private Sub btnOpenChildForm2_Click(sender As Object, e As EventArgs) Handles btnOpenChildForm2.Click
        'create new instance
        dialogForm = New ChildForm2()
    
        'show dialog
        If dialogForm.ShowDialog() = DialogResult.OK Then
            PageDetail.PageTitle = dialogForm.PageTitle
    
            'populate ComboBox
            PopulateChildForm1ComboBox(PageDetail.PageTitle)
        End If
    
        'dispose
        dialogForm.Dispose()
    
        dialogForm = Nothing
    End Sub
    

    Note: When using Option 1, the code for DialogForm_BtnAdd_Click and DialogForm_PassValue (in MainForm.vb) isn't used, so both of these methods can be removed.

    Option 2 (subscribe to btnAdd 'Click' event)

    Private Sub btnOpenChildForm2_Click(sender As Object, e As EventArgs) Handles btnOpenChildForm2.Click
        'create new instance
        dialogForm = New ChildForm2()
    
        'subscribe to events (add event handlers)
        AddHandler dialogForm.btnAdd.Click, AddressOf DialogForm_BtnAdd_Click
    
        'show dialog
        dialogForm.ShowDialog()
    
        'unsubscribe from events (remove event handlers)
        RemoveHandler dialogForm.btnAdd.Click, AddressOf DialogForm_BtnAdd_Click
    
        'dispose
        dialogForm.Dispose()
    
        dialogForm = Nothing
    End Sub
    

    Note: When using Option 2, the code for DialogForm_PassValue (in MainForm.vb) isn't used, so method DialogForm_PassValue can be removed.

    Option 3 (subscribe to event 'PassValue')

    Private Sub btnOpenChildForm2_Click(sender As Object, e As EventArgs) Handles btnOpenChildForm2.Click
        'create new instance
        dialogForm = New ChildForm2()
    
        'subscribe to events (add event handlers)
        AddHandler dialogForm.PassValue, AddressOf DialogForm_PassValue
    
        'show dialog
        dialogForm.ShowDialog()
    
        'unsubscribe from events (remove event handlers)
        RemoveHandler dialogForm.PassValue, AddressOf DialogForm_PassValue
    
        'dispose
        dialogForm.Dispose()
    
        dialogForm = Nothing
    End Sub
    

    Note: When using Option 3, the code for DialogForm_BtnAdd_Click (in MainForm.vb) isn't used, so method DialogForm_BtnAdd_Click can be removed.


    Here's a demo:

    在子表單中發送資料

    Resources:

    • Form.ShowDialog
    • Form.Show
    • How to populate a treeview from a list of objects

    轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/338813.html

    標籤:网络 winforms

    上一篇:手動將exe添加到控制面板中的程式和功能

    下一篇:隨機畫框排列

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more