主婦と.NETと犬のぶろぐ

奥様 と プログラム と お犬様 の 楽しい日常

目次

Blog 利用状況

ニュース

書庫

日記カテゴリ

GroupBox(System.Windows.Forms.GroupBox)

VB6.0 の時からお世話になってるコントロールです。
.NET Framework2.0 だと、AutoSize なるプロパティがあります。
今回はそいつで遊んでみました。


あと、関係ないんですけども、HTML で GroupBox っぽいのを実現するタグの名前をいつも忘れるので
メモ。fieldset(とほほのWWW入門)

ふじことえでんとかの人気投票 ふじこ
えでん
オット

■参考文献
GroupBox コントロール (Windows フォーム)
GroupBox クラス
AutoSizeMode 列挙体

■実行画像
AutoSize=False
GroupBox AutoSize=False
AutoSize=True
GroupBox AutoSize=True

Public Class GroupBoxTest

Private Sub GroupBoxTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList ' AutoSizeMode With Me.ComboBox1.Items .Add(System.Windows.Forms.AutoSizeMode.GrowAndShrink) .Add(System.Windows.Forms.AutoSizeMode.GrowOnly) End With
' 現在の GroupBox の値を ComboBox に設定 Me.CheckBox1.Checked = Me.GroupBox1.AutoSize Me.ComboBox1.Enabled = Me.CheckBox1.Checked Me.ComboBox1.SelectedItem = Me.GroupBox1.AutoSizeMode ' ComboBox が変更されたら、その値を GroupBox のプロパティに反映する AddHandler ComboBox1.SelectedIndexChanged, AddressOf Me.SetComboBoxValueToGroupBox
' Control を詰め込む。 For index As Integer = 1 To 10 Dim chk As CheckBox = New CheckBox() chk.Text = index.ToString() chk.Location = New Point(10, 20 * (index - 1) + 15) Me.GroupBox1.Controls.Add(chk) Next Me.GroupBox1.Text = "ふじことえでん~♪" End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged Me.ComboBox1.Enabled = Me.CheckBox1.Checked Me.SetComboBoxValueToGroupBox(sender, EventArgs.Empty) End Sub
' ComboBox とかの値を GroupBox の該当プロパティにセットする Private Sub SetComboBoxValueToGroupBox(ByVal sender As Object, ByVal e As System.EventArgs) Me.GroupBox1.AutoSize = Me.CheckBox1.Checked If Me.GroupBox1.AutoSize AndAlso Not Me.ComboBox1.SelectedItem Is Nothing Then Me.GroupBox1.AutoSizeMode = DirectCast(Me.ComboBox1.SelectedItem, AutoSizeMode) End If End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '' GroupBox 内の CheckBox の状態を一覧出力 'For Each ctrl As Control In Me.GroupBox1.Controls ' If TypeOf (ctrl) Is CheckBox Then ' Dim chk As CheckBox = DirectCast(ctrl, CheckBox) ' System.Diagnostics.Debug.WriteLine(chk.Text & ":" & chk.Checked.ToString()) ' End If 'Next
' 現在の GroupBox の大きさを表す四角形を描画 Dim rect As Rectangle = Me.GroupBox1.DisplayRectangle System.Diagnostics.Debug.WriteLine("Rectangle_H:" & rect.Size.Height.ToString()) System.Diagnostics.Debug.WriteLine("Rectangle_W:" & rect.Size.Width.ToString()) System.Diagnostics.Debug.WriteLine("GroupBox_H:" & Me.GroupBox1.Size.Height.ToString()) System.Diagnostics.Debug.WriteLine("GroupBox_W:" & Me.GroupBox1.Size.Width.ToString()) End Sub End Class

投稿日時 : 2007年1月23日 12:44

Feedback

# HVIHVWRXsTTZuRlhGP 2014/08/27 23:21 http://crorkz.com/

oYHzCf You must participate in a contest for probably the greatest blogs on the web. I'll suggest this website!

# VizgdJpXpAwNOZGXPfS 2014/08/29 12:02 http://nubiadesign.com/blog/

Very good written story. It will be useful to everyone who employess it, including me. Keep doing what you are doing - i will definitely read more posts.

# MZDoGzkmceYIBIoiiF 2014/09/08 18:07 http://www.arrasproperties.com/

Hi my loved one! I wish to say that this post is amazing, great written and include almost all vital infos. I'd like to look extra posts like this .

# MJjUVhdEPM 2014/09/09 7:29 http://vendere-su-internet.com/luis-souto/

Would you be interested by exchanging hyperlinks?

# zyIbqlPITYoLRWhOug 2014/09/14 17:44 http://www.escortsinlondon.tv/

Excellent web site. A lot of useful info here. I'm sending it to a few buddies ans additionally sharing in delicious. And obviously, thanks on your sweat!

タイトル  
名前  
Url
コメント