在WIN7 64位运行正常,在Windows server 2008 r2不显示OnPaint里面的内容

Mr Dang 2018-12-27 03:43:57
在WIN7 64位运行正常,在Windows server 2008 r2不显示OnPaint里面的内容,网上找了 说把WIN7 64电脑的gdiplus.dll放到程序根目录也没有用,这是什么问题 ?


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace VolumeShow
{
public partial class VolumeShow : UserControl
{
private VerticalProgressBar _progressbar = new VerticalProgressBar();
public VolumeShow()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
InitializeComponent();
OnForeColorChanged(EventArgs.Empty);
OnResize(EventArgs.Empty);

_progressbar.Minimum = 0;
_progressbar.Maximum = 100;
_progressbar.Left = pictureBox1.Left;
_progressbar.Width = 8;
_progressbar.Height = pictureBox1.Top-10;
this.Controls.Add(_progressbar);
}

public int Volume
{
get { return _progressbar.Value; }
set {
if (Math.Abs(_progressbar.Value - value) < 5) return;
_progressbar.Value = value>100 ? 100: value;
}
}

private void VolumeShow_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;

Point[] ps = new Point[3];
ps[0].X = _progressbar.Location.X + _progressbar.Width;
ps[0].Y = _progressbar.Location.Y;
ps[1].X = _progressbar.Location.X + _progressbar.Width;
ps[1].Y = pictureBox1.Top-10;
ps[2].X = _progressbar.Location.X + _progressbar.Width + 16;
ps[2].Y = _progressbar.Location.Y;
g.FillPolygon(new SolidBrush(Color.LightGray), ps);

Pen pen = new Pen(Color.LightGray,1);
g.DrawLine(pen, new Point(_progressbar.Location.X + _progressbar.Width, _progressbar.Location.Y),
new Point( _progressbar.Location.X + _progressbar.Width + 20, _progressbar.Location.Y));

g.DrawLine(pen, new Point(_progressbar.Location.X + _progressbar.Width, (pictureBox1.Top - 10)/2),
new Point(_progressbar.Location.X + _progressbar.Width + 20, (pictureBox1.Top - 10)/2));

g.DrawLine(pen, new Point(_progressbar.Location.X + _progressbar.Width, pictureBox1.Top - 10),
new Point(_progressbar.Location.X + _progressbar.Width + 20, pictureBox1.Top-10));
g.Dispose();
}
}
}

...全文
125 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mr Dang 2018-12-27
  • 打赏
  • 举报
回复
结贴,晕死了,原来是Color.LightGray这个颜色在windows server 2008是透明效果了
Mr Dang 2018-12-27
  • 打赏
  • 举报
回复
win7下的效果 ,window server 2008就不显示三角阴影
Mr Dang 2018-12-27
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VolumeShow
{
    public partial class VerticalProgressBar : ProgressBar
    {
        public VerticalProgressBar()
        {
            InitializeComponent();
        }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.Style |= 0x04;
                return cp;
            }
        }
    }
}

订阅的代码

namespace VolumeShow
{
    partial class VolumeShow
    {
        /// <summary> 
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region 组件设计器生成的代码

        /// <summary> 
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            this.pictureBox1.Image = global::VolumeShow.Properties.Resources.Volume_son_24px_1075745_easyicon_net;
            this.pictureBox1.InitialImage = null;
            this.pictureBox1.Location = new System.Drawing.Point(0, 199);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(28, 24);
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // VolumeShow
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.pictureBox1);
            this.Name = "VolumeShow";
            this.Size = new System.Drawing.Size(48, 226);
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.VolumeShow_Paint);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.PictureBox pictureBox1;

    }
}

xuzuning 2018-12-27
  • 打赏
  • 举报
回复
请贴全你的代码,以免误判
至少我没有看到订阅 Paint 事件的代码

另外,绘制的线条可能会被 _progressbar 全遮挡,请仔细核算
控件的尺寸会因皮肤方案的不同而变化

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧