C# と VB.NET の質問掲示板

ASP.NET、C++/CLI、Java 何でもどうぞ

ログ内検索
  • キーワードを複数指定する場合は 半角スペース で区切ってください。
  • 検索条件は、(AND)=[A かつ B] (OR)=[A または B] となっています。
  • [返信]をクリックすると返信ページへ移動します。
キーワード/ 検索条件 /
検索範囲/ 強調表示/ ON (自動リンクOFF)
結果表示件数/ 記事No検索/ ON
大文字と小文字を区別する

No.88350 の関連記事表示

<< 0 >>
■88350  Re[2]: C# PictureBoxクリックで画像切り替えが遅い…
□投稿者/ にゃるら -(2018/08/22(Wed) 13:43:26)
    魔界の仮面弁士さんの言うことを試してみようと思って以下のように書いてみました。
    
    環境はWin7(64bit)、VisualStudio2017、.Net4.6.1、C#です。
    画像はResources.resxを開いて、リソースの追加でImage6個分を1〜6の文字を書いたもので作成しました。
    
    自分の結果としては反応がいまいちでした。
    SizeModeがStretchImageなのが悪いのかもとNormalにしてもあまり変化はありませんでした。
    
    PictureBoxを使わない方がよいのかな?
    
    
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace WindowsFormsApp1
    {
        public partial class Form1 : Form
        {
            /// <summary>
            /// コンストラクタ
            /// </summary>
            public Form1()
            {
                InitializeComponent();
    
                this.imgtable = new Image[] {
                    Properties.Resources.Image1,
                    Properties.Resources.Image2,
                    Properties.Resources.Image3,
                    Properties.Resources.Image4,
                    Properties.Resources.Image5,
                    Properties.Resources.Image6,
                };
    
                ReplaceImage();
            }
    
            /// <summary>
            /// 必要なデザイナー変数です。
            /// </summary>
            private System.ComponentModel.IContainer components = null;
    
            #region Windows フォーム デザイナーで生成されたコード
    
            /// <summary>
            /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
            /// コード エディターで変更しないでください。
            /// </summary>
            private void InitializeComponent()
            {
                this.pictureBox1 = new System.Windows.Forms.PictureBox();
                ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
                this.SuspendLayout();
                // 
                // pictureBox1
                // 
                this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                | System.Windows.Forms.AnchorStyles.Left)
                | System.Windows.Forms.AnchorStyles.Right)));
                this.pictureBox1.Location = new System.Drawing.Point(34, 28);
                this.pictureBox1.Name = "pictureBox1";
                this.pictureBox1.Size = new System.Drawing.Size(721, 397);
                this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                this.pictureBox1.TabIndex = 0;
                this.pictureBox1.TabStop = false;
                this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(800, 450);
                this.Controls.Add(this.pictureBox1);
                this.Name = "Form1";
                this.Text = "Form1";
                ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
                this.ResumeLayout(false);
    
            }
    
            #endregion
    
            private System.Windows.Forms.PictureBox pictureBox1;
    
            /// <summary>
            /// 使用中のリソースをすべてクリーンアップします。
            /// </summary>
            /// <param name="disposing">マネージ リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
    
                if (this.imgtable != null)
                {
                    foreach (var img in this.imgtable)
                    {
                        img?.Dispose();
                    }
                    this.imgtable = null;
                }
    
                base.Dispose(disposing);
            }
    
            private Image[] imgtable;
            private int ClickCount = 0;
    
            private void pictureBox1_Click(object sender, EventArgs e)
            {
                ++ClickCount;
                ReplaceImage();
            }
    
            private void ReplaceImage()
            {
                if (this.imgtable != null)
                {
                    var index = ClickCount % this.imgtable.Length;
                    this.pictureBox1.Image = imgtable[index];
                }
            }
        }
    }
    
記事No.88341 のレス /過去ログ152より / 関連記事表示
削除チェック/



<< 0 >>

パスワード/

- Child Tree -