• ベストアンサー

OnPaintメソッドが実行されずに、困っています

JScript .NET に関する質問なので、カテゴリが違うと思いますが、ご存知の方がいらっしゃったらよろしくお願いします。 import Accessibility; import System.Drawing; import System.Windows.Forms; new Form1().ShowDialog(); class Form1 extends Form { function Form1() { Text = "Form1"; BackColor = SystemColors.Window; ForeColor = SystemColors.WindowText; ResizeRedraw = true; } protected function OnPaint(e) { var g = e.Graphics; var pen = new Pen(ForeColor); g.DrawLine(pen, 0, 0, ClientSize.Width - 1, ClientSize.Height - 1); g.DrawLine(pen, 0, ClientSize.Height - 1, ClientSize.Width - 1, 0); } }

質問者が選んだベストアンサー

  • ベストアンサー
noname#49664
noname#49664
回答No.2

描画メソッドですが。 protected override function OnPaint(e:PaintEventArgs) { var g = e.Graphics; var pen = new Pen(ForeColor); var w = ClientSize.Width; var h = ClientSize.Height; g.DrawLine(pen, new Point(0,0), new Point(w - 1,h - 1)); g.DrawLine(pen, new Point(0, h - 1), new Point(w - 1, 0)); } これではどうでしょう?

全文を見る
すると、全ての回答が全文表示されます。

その他の回答 (1)

  • PED02744
  • ベストアンサー率40% (157/390)
回答No.1

JScriptはよくわかりませんが、普通の.NETで検索すればいいのかな。 http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/cpref/html/frlrfsystemwindowsformscontrolclasspainttopic.asp JScriptでは、ペイントイベントの独自定義ができないとかかれていますが、関係ありそうですか?

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • Androidアプリ実行エラー2

    Androidアプリ実行エラー ソースはこちらです。 package com.example.sudoku; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Paint.FontMetrics; import android.graphics.Paint.Style; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.animation.AnimationUtils; public class PuzzleView extends View { private static final String TAG = "Sudoku"; private float width; private float height; private int selX; private int selY; private final Rect selRect = new Rect(); private final Game game; public PuzzleView(Context context) { super(context); this.game = (Game) context; setFocusable(true); setFocusableInTouchMode(true); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { width = w / 9f; height = h / 9f; getRect(selX, selY, selRect); Log.d(TAG, "onSizeChanged: width " + width + ", height" + height); super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { //背景色の描画 Paint background = new Paint(); background.setColor(getResources().getColor( R.color.puzzle_background)); canvas.drawRect(0, 0, getWidth(), getHeight(), background); //盤面を描画する //枠線の色を定義する Paint dark = new Paint(); dark.setColor(getResources().getColor(R.color.puzzle_dark)); Paint hilite = new Paint(); hilite.setColor(getResources().getColor(R.color.puzzle_hilite)); Paint light = new Paint(); light.setColor(getResources().getColor(R.color.puzzle_light)); //マス目を区切る線 for (int i = 0; i < 9; i++) { canvas.drawLine(0, i * height, getWidth(), i * height, light); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, hilite); canvas.drawLine(i * width, 0, i * width, getHeight(), light); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), hilite); } //3*3を区切る線 for (int i = 0; i < 9; i++) { if(i % 3 != 0) continue; canvas.drawLine(0, i * height, getWidth(), i * height, dark); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, hilite); canvas.drawLine(i * width, 0, i * width, getHeight(), dark); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), hilite); } //数値を描画する Paint foreground = new Paint(Paint.ANTI_ALIAS_FLAG); foreground.setColor(getResources().getColor(R.color.puzzle_foreground)); foreground.setStyle(Style.FILL); foreground.setTextSize(height * 0.75f); foreground.setTextScaleX(width / height); foreground.setTextAlign(Paint.Align.CENTER); //マスの中央に数字を描く FontMetrics fm = foreground.getFontMetrics(); //x軸方向でセンタリングする。中央のx座標に揃える float x = width / 2; // float y = height / 2 - (fm.ascent + fm.descent) / 2; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { canvas.drawText(this.game.getTileString(i, j),i * width + x, j * height + y, foreground); } } //ヒントを描画する //選択されたマスを描画する } private void getRect(int x, int y, Rect rect) { rect.set((int) (x * width), (int) (y * height), (int) (x * width + width), (int) (y * height + height)); } } ログはこちらです。 ご回答をよろしくお願いします。 http://okwave.jp/qa/q8272113.html

  • これを正確に実行したいのですが

    再びすみません。 下のプログラムなのですが。コンパイルはできるのに 図が表示されず、終わらず、実行がおかしなことになってしまいます。どこを直したらいいのでしょうか? お願い致します。 import java.awt import java.awt.event.*; class gazou extends Frame { public gazou(){ setSize(300,200); addWindowListener(new WindowAdapter( ) public void windowClosing(WindowEvent e) System.exit(0); } }); } public void paint(Graphics g) g.drawRect(40,40,50,50); g.drawRoundRect(100,40,50,50,10,10); g.drawOval(160,40,50,50); g.drawArc(220,40,50,50,45,270); g.fillRect(40,100,50,50); g.fillRoundRect(100,100,50,50,10,10); g.fillOval(160,100,50,50); g.fillArc(220,100,50,50,45,270); g.drawLine(40,180,260,180); } } public class kadai19{ public static void main(String[] args) { Frame w = new Frame(); w.show( ); } }

    • ベストアンサー
    • Java
  • C#で派生クラスから描画処理を行う

    C#を勉強しているのですが、GUIを作り初めて描画処理で分からない所があり、質問させて頂きます。 基本クラスの方で「Hello, world!」という文字列をDrawStringで表示させる事は出来たのですが、それを基本クラスを継承した派生クラスのメソッドで行うと何も表示されないんです。 以下が試したコードです。 //基本クラスSample1 using System; using System.Drawing; using System.Windows.Forms; public class Sample1 : Form {   protected Bitmap image; protected Graphics g; protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Sample2 s = new Sample2(); s.helloworld(); e.Graphics.DrawImage(image, 0, 0); } public Sample1() { SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); image = new Bitmap(600, 400); g = Graphics.FromImage(image); } static void Main() { Form form = new Sample1(); form.Text = "sample"; form.ClientSize = new Size(600, 400); form.BackColor = Color.FromArgb(0xff, 0xff, 0xff); Application.Run(form); } } //派生クラスSample2 using System; using System.Drawing; using System.Windows.Forms; public class Sample2 : Sample1 { Brush brush = new SolidBrush(Color.Black); public void helloworld() { g.DrawString("Hello, world!", this.Font, brush, 10, 10); } } なぜ表示されないのか分かる方いらしたら、ご教授願えないでしょうか。是非お願いします。

  • なぜprotected overrideなのか

    C#でわからないことが2,3あるのですが、このmsndのサンプルで public class FirstControl : Control{ public FirstControl() {} protected override void OnPaint(PaintEventArgs e) { // Call the OnPaint method of the base class. base.OnPaint(e); // Call methods of the System.Drawing.Graphics object. e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), ClientRectangle); } } これのprotected override void OnPaint(PaintEventArgs e){} の部分なのですが、なぜprotected overrinde修飾子なのでしょう 何をオーバーライドしてるのですか?他のサンプルにも構文のように出てくるのですが。 あとOnPaintはメソッドのようですがイベントを発生させるにはデリゲートではないのでしょうか あとPaintEventArgsはクラスということですがnewはいらないのでしょうか。staticがどこかにあるのでしょうか よろしくお願いします。

  • 猫でもわかるの C# の第3章で質問なのですが

    g.DrawLine(new Pen(Color.Red, 5f), 10, 100, 200, 100); ではコンパイルが通るのですが g.DrawLine(new Pen(Color.Red, 5f), new Point(10, 50), new Point(180, 50)); ではコンパイルが通りません 検索などもしてみたのですが理由が見つからなくて よろしければ教えていただけないでしょうか

  • Visual C# 2008 Express Editionで実行するとDOS窓が出る

    私はC#でフォームプログラミングを勉強しようと思い、「Visual C# 2008 Express Edition」をダウンロードして、取り合えずウィンドウを作るだけの簡単なプログラムを実行してみたのですが、ウィンドウと同時に黒い窓(DOS窓というのでしょうか)が現れてしまいます。 作成したアプリケーションデータを実行しても、やはり黒い画面が出てしまい困っています。 本に掲載されていたコードをウィンドウタイトルを変えて、そのままビルドしただけですし、本に付いてきたCD-ROMの中の同じサンプルプログラムのアプリケーションデータを実行しても、黒い画面は現れません。何か方法に誤りがあるのでしょうか、分かる方がいたら教えて頂きたいのですが、下がコードです。 using System; using System.Drawing; using System.Windows.Forms; public class Test : Form { protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); } static void Main() { Form form = new Test(); form.Text = "ウィンドウタイトル"; form.ClientSize = new Size(600, 400); form.BackColor = Color.FromArgb(0xff, 0xff, 0xff); Application.Run(form); } } 参照設定には、 System System.Drawing System.Windows.Forms を含めています。

  • setColorメソッド の使い方

    import java.applet.Applet; import java.awt.*; import java.awt.event.*; /* <APPLET CODE= "JaRadio1.class" WIDTH=300 HEIGHT=150> </APPLET> */ public class JaRadio1 extends Applet implements ItemListener{ CheckboxGroup grp1; Checkbox bx1,bx2,bx3; int r=255,g=255,b=255; String ss =""; public void init(){ grp1=new CheckboxGroup(); bx1=new Checkbox("Red",true,grp1); bx2=new Checkbox("Green",false,grp1); bx3=new Checkbox("Blue",false,grp1); bx1.addItemListener(this); bx2.addItemListener(this); bx3.addItemListener(this); add(bx1); add(bx2); add(bx3); } public void itemStateChanged(ItemEvent e){ r=g=b=0; if(bx1.getState()==true){ r=255; } if(bx2.getState()==true){ g=255; } if(bx3.getState()==true){ b=255; } ss=("Red="+r+" Green="+g+" Blue="+b); repaint(); } public void paint(Graphics g){ g.drawString(ss,30,40); // g.setColor(new Color(r,g,b)); g.fillOval(30,60,80,30); } } g.setColor(new Color(r,g,b)); により色つき図形を 赤緑青をチェックボックスで選択して 描きたいのですが この部分でエラーがでてしまいます。 上記のように//によりコメントアウトするとコンパイルできます どこが間違っているのかどうしてもわかりません よろしくお願いします。

  • f(x)=xのf'(x)と∫f(x)dxのグラフ化

    f(x)=xのf'(x)と∫f(x)dxのグラフ化したいのですがここからどうすればいいのか分からず足踏みしてます。ご教授ください。 積分区間は0~xです。 import java.awt.*; import java.awt.event.*; public class graphics0 extends Frame { // コンストラクタ public graphics0(){ setSize(500, 500); setVisible(true); setTitle("graphics0"); // メッセージ処理 addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } // メインメソッド public static void main(String[] args){ new graphics0(); } // ペイントメソッド public void paint(Graphics g){ //ここに絵をかくコードを書く // 中心座標 int ox = 250; int oy = 250; // グラフの幅 int width = 200; int height = 200; //直線描画のための2点(x0,y0), (x1, y1) double x0, y0; double x1, y1; // 刻み幅 double d = 0.001; double n = (int) (1.0 / d); // 軸の描画 g.drawLine(50, 250, 450, 250); g.drawLine(250, 50, 250, 450); x0 = 0; y0 = 0; x1 = d; for(int i = 0; i < n; i++){ y1 = x1 * x1; g.drawLine( (int) (x0 * width) + ox, -((int)(y0 * height) -oy), (int) (x1 * width) + ox, -((int) (y1 * height) - oy)); x0 += d; x1 += d; y0 = y1; } } } よろしくお願いいたします。

  • openWin の width, height に変数は使える?

    JavaScript の openWindow で ウィンドウのサイズ指定に変数を使うことは可能でしょうか? もしかすると数字として渡したものが文字として扱われてるような 気がするのですが、どなたかご存知でしょうか? width2, height2 に入れなおしたり eval() を使ってみたのですがうまくいきません。。。 width, height を 300 と直接指定した場合は動作します。 ブラウザは IE6, code はこちらです。 <html> <head> <title>[ ]</title> <meta http-equiv="content-type" content="text/html; charset=shift-jis"> <meta http-equiv="imagetoolbar" content="no"> <script language="JavaScript"><!-- function openWin(src, width1, height1) { var width2 = width1; var height2 = height1; width1 = eval(width1); height1 = eval(height1); window.open(src,'','directories=0, location=0, menubar=0, scrollbars=0, status=1, toolbar=0, resizable=1, width=width1, height=height1'); document.form1.text1.value = src + width1 + height1; return false; } //--></script> </head> <body topmargin="0" leftmargin="0" vlink="blue" alink="blue"> <a href="#" onclick="openWin('http://www.google.co.jp', 300, 300);">window</a> <form name="form1"> <input type="text" name="text1" size="40"> </form> </body> </html>

  • javascriptでの値の取得について

    すごく素人だと思うのですが。 この手のタイプで得られる値を外部で取得できないのでしょうか? 戻り値で返すわけにもいかないですし、よく理解できていません var val: ○.○=function(){ここで得た値をvalに入れたい} 例1 var target; ・・・ request.onreadystatechange=function(){ if(request.readyState==4 && request.status==200){ //target=request.responseText;みたいなことをしたい } } 例2 var width,height; ・・・ image.onload=function(){ //width=image.width; height=image.height;みたいなことをしたい }