当前位置: 代码迷 >> VB Dotnet >> 窗体的有关问题,还是没有解决
  详细解决方案

窗体的有关问题,还是没有解决

热度:71   发布时间:2016-04-25 02:11:48.0
窗体的问题,还是没有解决!
本帖最后由 laomms 于 2014-09-12 23:41:04 编辑

dim n as Integer
        If n= 1 Then
            QingDang = "销售清单号"
            Dim frm As SaleBill = CType(Application.OpenForms("SaleBill"), SaleBill)     '窗体1
       ElseIf n= 5 Then
            QingDang = "进货清单号"
            Dim frm As BuyBill = CType(Application.OpenForms("BuyBill"), BuyBill)     '窗体2
        End If

 frm.ListView1.Items.Clear()
sql = "Select * from 销售单 where " & QingDang & " like '" &  frm.销售清单号.Text & "'"
...
          frm.型号.Text = "型号1 "                                               'SaleBill.型号.Text = "型号1 " 或者  BuyBill.型号.Text = "型号1 "
          If n = 1 Then               
                frm.数量.Text ="销售数量  "
                frm.价格.Text ="     "
                frm.金额.Text ="     "
         elseif n=2 then
                 frm.数量.Text ="进货数量  "
                frm.价格.Text ="     "
                frm.金额.Text ="     "
           end if



如何让frm能够引用或者设置SaleBill或者BuyBill的控件值。
------解决思路----------------------
不过楼主,要想问题少,并且自己能解决问题,建议还是找本教材系统学习下。关靠搜索,得来的知识太片断化。缺乏体系,随便出个问题都不知道怎么办,都要再去搜,虽然现在搜索很强大,可是有些技巧性的东西,靠搜索也不是全能解决的。


------解决思路----------------------
system.windows.forms.form里面有个controls的collection,里面放了窗体上所有的控件,
但是,注意这个collection是从System.Windows.Forms.Control继承过来的,所以,如果你窗口上的空间放在panel之类的里面的话,单纯遍历form的controls是没用的,要继续遍历panel的control
------解决思路----------------------

另一种方法是如下所示;


Imports System.Data.Sql
Public Class Form1
    Private frm As New Form
 Private sql As String
    Private QingDang As String
    Private n As Integer 
     
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        frm.ListView1.Items.Clear()
        frm.型号.Text = "型号1 "                                               'SaleBill.型号.Text = "型号1 " 或者  BuyBill.型号.Text = "型号1 "
        If n = 1 Then
            QingDang = "销售清单号"
            Dim frm As SaleBill = CType(Application.OpenForms("SaleBill"), SaleBill)     '窗体1
          Sql = "Select * from 销售单 where " & QingDang & " like '" & frm.销售清单号.Text & "'"
            frm.数量.Text = "销售数量  "
            frm.价格.Text = "     "
            frm.金额.Text = "     "
  
        ElseIf n = 2 Then
           
QingDang = "进货清单号"
            Dim frm As BuyBill = CType(Application.OpenForms("BuyBill"), BuyBill)     '窗体2