画面に楕円を描画するためにOnPaintメソッドをオーバーライドしました。
protected override void OnPaint(PaintEventArgs e)
{
MessageBox.Show("Paint");
if (debugStarted)
{
int y = rtbLogicCode.PlaceToPoint(new Place(0, debugLine)).Y;
if (rtbLogicCode.GetVisibleState(debugLine).ToString() == "Visible")
{
e.Graphics.FillEllipse(new LinearGradientBrush(new Rectangle(0, y, 15, 15), Color.LightPink, Color.Red, 45), 0, y, 15, 15);
}
base.OnPaint(e);
}
}
private void rtbLogicCode_Scroll(object sender, ScrollEventArgs e)
{
this.Invalidate();
}
スクロールイベント(リッチテキストボックス上)は適切に処理されますが、フォームを無効にしているのに、OnPaint関数を呼び出していません(メッセージボックスが表示されていません)。
これの考えられる原因は何でしょうか?
編集:子フォームの初期化関数(MDIプロパティを使用してメインフォームのコントロールとして追加)で、次のスタイルを設定したことを忘れました。
private void LogicCodeInit()
{
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
}
Edit2:子フォームがTabControlのコントロールとして追加されていることにも言及するのを忘れました。次に、TabControlがメインフォームのコントロールとして追加されます。