powered by simpleCommunicator - 2.0.56     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / как вместо консольного окна реализвать вывод в TextBox?
2 сообщений из 2, страница 1 из 1
как вместо консольного окна реализвать вывод в TextBox?
    #38621149
Vova_1805
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Среда Visual Basic STUDIO’2010 Professional
Как в среде VB NET
В ниже приведенных процедурах в консольном приложении
заменить вывод вместо чёрного окна
в контрол типа TextBox, имя которого, пускай, xmlDisplay?
Спасибо.
Имеем 3 файла
file Program.vb
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
Namespace Samples
    Class Program
        Shared Sub Main()
        Dim dbPath As String = System.IO.Path.GetFullPath(System.IO.Path.Combine(Application.StartupPath, "..\..\Data\NORTHWIND.MDF"))
            Dim sqlServerInstance As String = ".\SQLEXPRESS"
            Dim connString As String = "AttachDBFileName='" + dbPath + "';Server='" + sqlServerInstance + "';user instance=true;Integrated Security=SSPI;"

            Dim path As String = System.IO.Path.GetFullPath(System.IO.Path.Combine(Application.StartupPath, "..\..\Northwind.xml"))
            Dim mappingSource As XmlMappingSource = XmlMappingSource.FromXml(File.ReadAllText(path))
            Dim db As Northwind = New Northwind(connString, mappingSource)
            db.Log = Console.Out
            Samples.Sample10(db) ' как выводить, допустим в TextBox
        End Sub
    End Class
End Namespace 


File " Samples.vb" содержит:
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Public Class Samples
Public Shared Sub Sample10(ByVal db As Northwind)
            ' Используйте оператор группировки (Group By) и статистические функции, такие как Min() и Max(), для вычисления значений по разделам групп
            Dim q = From p In db.Products _
                    Group p By p.CategoryID Into Group _
                    Select New With { _
                        .Category = CategoryID, _
                        .MinPrice = Group.Min(Function(p) p.UnitPrice), _
                        .MaxPrice = Group.Max(Function(p) p.UnitPrice) _
                        }
            ObjectDumper.Write(q, 1)
        End Sub
End Class


File "ObjectDumper.vb" содержит:

Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
Public Class ObjectDumper
    Public Shared Sub Write(ByVal o As Object)
        Write(o, 0)
    End Sub

Public Shared Sub Write(ByVal o As Object, ByVal depth As Integer)
        Write(o, depth, Console.Out) 
    End Sub

Public Shared Sub Write(ByVal o As Object, ByVal depth As Integer, ByVal log As TextWriter)
        Dim dumper As New ObjectDumper(depth)
        dumper.writer = log 
        dumper.WriteObject(Nothing, o)
End Sub 

Private Sub WriteObject(ByVal prefix As String, ByVal o As Object)
        If (o Is Nothing OrElse TypeOf o Is ValueType OrElse TypeOf o Is String) Then
            WriteIndent()
            Write(prefix)
            MsgBox("prefix = " + prefix)

            WriteValue(o)
            WriteLine()
        ElseIf TypeOf o Is IEnumerable Then
            For Each element As Object In CType(o, IEnumerable)
                 If (TypeOf element Is IEnumerable AndAlso Not TypeOf element Is String) Then
                    WriteIndent()
                    Write(prefix)
                    Write("...")
                    WriteLine()
                    If (level < depth) Then
                        level += 1
                        WriteObject(prefix, element)
                        level -= 1
                    End If
                Else
                    WriteObject(prefix, element)
                End If
            Next
        Else
            Dim t As Type
            Dim members As MemberInfo() = o.GetType.GetMembers((BindingFlags.Public Or BindingFlags.Instance))
            WriteIndent()
            Write(prefix)
            Dim propWritten As Boolean = False

            For Each m As MemberInfo In members
                Dim f As FieldInfo = TryCast(m, FieldInfo)
                Dim p As PropertyInfo = TryCast(m, PropertyInfo)
                If (f IsNot Nothing OrElse p IsNot Nothing) Then
                    If propWritten Then
                        WriteTab()
                    Else
                        propWritten = True
                    End If
                    Write(m.Name)
                    Write("=")
                    If (f IsNot Nothing) Then
                        t = f.FieldType
                    Else
                        t = p.PropertyType
                    End If

                    If (t.IsValueType OrElse t Is GetType(String)) Then
                        If (f IsNot Nothing) Then
                            WriteValue(f.GetValue(o))
                        Else
                            WriteValue(p.GetValue(o, Nothing))
                        End If
                    ElseIf GetType(IEnumerable).IsAssignableFrom(t) Then
                        Write("...")
                    Else
                        Write("{ }")
                    End If
                    End If
            Next
            If propWritten Then WriteLine()

            If (level < depth) Then
                For Each m As MemberInfo In members
                    Dim f As FieldInfo = TryCast(m, FieldInfo)
                    Dim p As PropertyInfo = TryCast(m, PropertyInfo)
                    If (f IsNot Nothing OrElse p IsNot Nothing) Then
                        If (f IsNot Nothing) Then
                            t = f.FieldType
                        Else
                            t = p.PropertyType
                        End If

                        If (Not (t.IsValueType OrElse t Is GetType(String))) Then
                            Dim value As Object
                            If (f IsNot Nothing) Then
                                value = f.GetValue(o)
                            Else
                                value = p.GetValue(o, Nothing)
                            End If
                            If (value IsNot Nothing) Then
                                level += 1
                                WriteObject((m.Name & ": "), value)
                                level -= 1
                            End If
                        End If
                    End If
                Next
            End If
        End If
    End Sub
...
Рейтинг: 0 / 0
как вместо консольного окна реализвать вывод в TextBox?
    #38621806
Фотография pation
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Vova_1805,

в качестве лога используй стрим, кот. будет писать в текстбокс
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / как вместо консольного окна реализвать вывод в TextBox?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]