Nasıl yapılır: Windows Forms RichTextBox Denetiminde Biçimlendirme Öznitelikleri Değiştiğinde Belirleme
Windows Forms Windows yaygın olarak kullanılan bir kullanım, metni yazı tipi seçenekleri RichTextBox veya paragraf stilleri gibi özniteliklerle biçimlendirmektir. Birçok sözcük işleme uygulamasında olduğu gibi, uygulamanın araç çubuğunu görüntüleme amacıyla metin biçimlendirmedeki değişiklikleri izlemesi gerekir.
Biçimlendirme özniteliklerinde yapılan değişikliklere yanıt vermek için
Özniteliğin SelectionChanged değerine bağlı olarak uygun bir eylem gerçekleştirmek için olay işleyicisinde kod yazın. Aşağıdaki örnek, özelliğin değerine bağlı olarak bir araç çubuğu düğmesinin görünümünü SelectionBullet değiştirir. Araç çubuğu düğmesi yalnızca ekleme noktası denetime taşındığında güncelleştirilir.
Aşağıdaki örnekte, denetime sahip bir RichTextBox formun ve araç çubuğu ToolBar düğmesi içeren bir denetimin olduğu varsayıldığında. Araç çubukları ve araç çubuğu düğmeleri hakkında daha fazla bilgi için bkz. Nasıl ekleyebilirsiniz: ToolBar Denetimine Düğme Ekleme.
' The following code assumes the existence of a toolbar control ' with at least one toolbar button. Private Sub RichTextBox1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.SelectionChanged If RichTextBox1.SelectionBullet = True Then ' Bullet button on toolbar should appear pressed ToolBarButton1.Pushed = True Else ' Bullet button on toolbar should appear unpressed ToolBarButton1.Pushed = False End If End Sub// The following code assumes the existence of a toolbar control // with at least one toolbar button. private void richTextBox1_SelectionChanged(object sender, System.EventArgs e) { if (richTextBox1.SelectionBullet == true) { // Bullet button on toolbar should appear pressed toolBarButton1.Pushed = true; } else { // Bullet button on toolbar should appear unpressed toolBarButton1.Pushed = false; } }// The following code assumes the existence of a toolbar control // with at least one toolbar button. private: System::Void richTextBox1_SelectionChanged( System::Object ^ sender, System::EventArgs ^ e) { if (richTextBox1->SelectionBullet == true) { // Bullet button on toolbar should appear pressed toolBarButton1->Pushed = true; } else { // Bullet button on toolbar should appear unpressed toolBarButton1->Pushed = false; } }