在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C#自定义饼图控件 GDI+ 示例源码

C#自定义饼图控件 GDI+ 示例源码

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.24M
  • 下载次数:109
  • 浏览次数:664
  • 发布时间:2017-06-17
  • 实例类别:C#语言基础
  • 发 布 人:xiazai3099
  • 文件格式:.zip
  • 所需积分:0
 相关标签: GDI C#

实例介绍

【实例简介】PieChart C#编码

【实例截图】

【核心代码】

/// Author:  Matthew Johnson
/// Version: 1.0
/// Date:    March 13, 2006
/// Notice:  You are free to use this code as you wish.  There are no guarantees whatsoever about
/// its usability or fitness of purpose.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Nexus.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing.Printing;

namespace PieChartTest
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();

      PieChart1.Items.Add(new PieChartItem(10, Color.BurlyWood, "Tan", "Tan tool tip", 0));
      PieChart1.Items.Add(new PieChartItem(10, Color.Gold, "Gold", "Gold tool tip", 0));
      PieChart1.Items.Add(new PieChartItem(10, Color.Chocolate, "Brown", "Brown tool tip", 50));
      PieChart1.Items.Add(new PieChartItem(20, Color.DarkRed, "Red", "Red tool tip", 0));


      PieChart1.ItemStyle.SurfaceAlphaTransparency = 0.75F;
      PieChart1.FocusedItemStyle.SurfaceAlphaTransparency = 0.75F;
      PieChart1.FocusedItemStyle.SurfaceBrightnessFactor = 0.3F;

      cmbTextMode.Items.Add(PieChart.TextDisplayTypes.Always);
      cmbTextMode.Items.Add(PieChart.TextDisplayTypes.FitOnly);
      cmbTextMode.Items.Add(PieChart.TextDisplayTypes.Never);
      cmbTextMode.SelectedIndex = 0;

      trkRotation.Value = (int)(PieChart1.Rotation * 180 / Math.PI);
      trkIncline.Value = (int)(PieChart1.Inclination * 180 / Math.PI);
      trkThickness.Value = (int)(PieChart1.Thickness);
      trkRadius.Value = (int)(PieChart1.Radius);

      trkEdgeBrightness.Value = (int)(PieChart1.ItemStyle.EdgeBrightnessFactor * 100);
      trkFocusedEdgeBrightness.Value = (int)(PieChart1.FocusedItemStyle.EdgeBrightnessFactor * 100);
      trkSurfaceBrightness.Value = (int)(PieChart1.ItemStyle.SurfaceBrightnessFactor * 100);
      trkFocusedSurfaceBrightness.Value = (int)(PieChart1.FocusedItemStyle.SurfaceBrightnessFactor * 100);
      trkSurfaceTransparency.Value = (int)(PieChart1.ItemStyle.SurfaceAlphaTransparency * 100);
      trkFocusedSurfaceTransparency.Value = (int)(PieChart1.FocusedItemStyle.SurfaceAlphaTransparency * 100);

      chkAutoSizeRadius.Checked = PieChart1.AutoSizePie;
      chkShowEdges.Checked = PieChart1.ShowEdges;
      chkShowToolTips.Checked = PieChart1.ShowToolTips;

      cmbTextMode.SelectedItem = PieChart1.TextDisplayMode;

      propertyGrid1.SelectedObject = new ItemCollectionProxy(PieChart1);
    }

    private void trkRotation_Scroll(object sender, EventArgs e)
    {
      PieChart1.Rotation = (float)(trkRotation.Value * Math.PI / 180);
    }

    private void trkIncline_Scroll(object sender, EventArgs e)
    {
      PieChart1.Inclination = (float)(trkIncline.Value * Math.PI / 180);
    }

    private void trkThickness_Scroll(object sender, EventArgs e)
    {
      PieChart1.Thickness = trkThickness.Value;
    }

    private void trkRadius_Scroll(object sender, EventArgs e)
    {
      PieChart1.Radius = trkRadius.Value;
    }

    private void PieChart1_AutoSizePieChanged(object sender, EventArgs e)
    {
      trkRadius.Enabled = !PieChart1.AutoSizePie;
    }

    private void chkAutoSizeRadius_CheckedChanged(object sender, EventArgs e)
    {
      PieChart1.AutoSizePie = chkAutoSizeRadius.Checked;
    }

    private void chkShowEdges_CheckedChanged(object sender, EventArgs e)
    {
      PieChart1.ShowEdges = chkShowEdges.Checked;
    }

    private void chkShowToolTips_CheckedChanged(object sender, EventArgs e)
    {
      PieChart1.ShowToolTips = chkShowToolTips.Checked;
    }

    private void trkSurfaceTransparency_Scroll(object sender, EventArgs e)
    {
      PieChart1.ItemStyle.SurfaceAlphaTransparency = (float)trkSurfaceTransparency.Value / 100;
    }

    private void trkFocusedSurfaceTransparency_Scroll(object sender, EventArgs e)
    {
      PieChart1.FocusedItemStyle.SurfaceAlphaTransparency = (float)trkFocusedSurfaceTransparency.Value / 100;
    }

    private void trkEdgeBrightness_Scroll(object sender, EventArgs e)
    {
      PieChart1.ItemStyle.EdgeBrightnessFactor = (float)trkEdgeBrightness.Value / 100;
    }

    private void trkFocusedEdgeBrightness_Scroll(object sender, EventArgs e)
    {
      PieChart1.FocusedItemStyle.EdgeBrightnessFactor = (float)trkFocusedEdgeBrightness.Value / 100;
    }

    private void trkSurfaceBrightness_Scroll(object sender, EventArgs e)
    {
      PieChart1.ItemStyle.SurfaceBrightnessFactor = (float)trkSurfaceBrightness.Value / 100;
    }

    private void trkFocusedSurfaceBrightness_Scroll(object sender, EventArgs e)
    {
      PieChart1.FocusedItemStyle.SurfaceBrightnessFactor = (float)trkFocusedSurfaceBrightness.Value / 100;
    }

    private void cmbTextMode_SelectedIndexChanged(object sender, EventArgs e)
    {
      if (cmbTextMode.SelectedItem != null)
        PieChart1.TextDisplayMode = (PieChart.TextDisplayTypes)cmbTextMode.SelectedItem;
    }

    private void OnItemFocusChanging(object sender, PieChart.PieChartItemFocusEventArgs e)
    {
      if (e.NewItem != null && e.NewItem.Text != null)
        this.Text = "PieChartTest - "   e.NewItem.Text;
      else
        this.Text = "PieChartTest - [no item focused]";
    }

    private void OnItemClicked(object sender, PieChart.PieChartItemEventArgs e)
    {
      if (e.Item.Tag == null || (bool)e.Item.Tag == true)
      {
        e.Item.Offset  = 50;
        e.Item.Tag = false;
      }
      else
      {
        e.Item.Offset = Math.Max(0, e.Item.Offset - 50);
        e.Item.Tag = true;
      }
    }

    private void mnuFileSaveAs_Click(object sender, EventArgs e)
    {
      SaveFileDialog dlg = new SaveFileDialog();
      dlg.Filter = "PNG Image|*.png|JPEG Image|*.jpg;*.jpeg|Bitmap Image|*.bmp|GIF Image|*.gif";

      Size imageSize;
      if (PieChart1.AutoSizePie)
        imageSize = new Size(PieChart1.Bounds.Width, PieChart1.Bounds.Height);
      else
        imageSize = PieChart1.GetChartSize(PieChart1.Padding);

      if (dlg.ShowDialog() == DialogResult.OK)
      {
        switch (dlg.FilterIndex)
        {
          case 1:
            PieChart1.SaveAs(dlg.FileName, ImageFormat.Png, imageSize, PieChart1.Padding);
            break;
          case 2:
            PieChart1.SaveAs(dlg.FileName, ImageFormat.Jpeg, imageSize, PieChart1.Padding);
            break;
          case 3:
            PieChart1.SaveAs(dlg.FileName, ImageFormat.Bmp, imageSize, PieChart1.Padding);
            break;
          case 4:
            PieChart1.SaveAs(dlg.FileName, ImageFormat.Gif, imageSize, PieChart1.Padding);
            break;
          default:
            throw new Exception("Unknown file filter.");
        }
      }
    }

    private void mnuFilePrint_Click(object sender, EventArgs e)
    {
      PrintDialog dlg = new PrintDialog();
      dlg.Document = new PrintDocument();
      PieChart1.AttachPrintDocument(dlg.Document);

      if (dlg.ShowDialog() == DialogResult.OK)
      {
        dlg.Document.Print();
      }
    }

    private void mnuFileExit_Click(object sender, EventArgs e)
    {
      this.Close();
    }
  }
}

标签: GDI C#

实例下载地址

C#自定义饼图控件 GDI+ 示例源码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警