⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gradientfill.cs

📁 微软的行业应用解决方案示例
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace HardwareDistributor.Utilities
{
	public sealed class GradientFill
	{
		// This method wraps the PInvoke to GradientFill.
		// Parmeters:
		//  gr - The Graphics object we are filling
		//  rc - The rectangle to fill
		//  startColor - The starting color for the fill
		//  endColor - The ending color for the fill
		//  fillDir - The direction to fill
		//
		// Returns true if the call to GradientFill succeeded; false
		// otherwise.
		public static bool Fill(
			Graphics gr,
			Rectangle rc,
			Color startColor, Color endColor,
			FillDirection fillDir)
		{

			// Initialize the data to be used in the call to GradientFill.
			Native.TRIVERTEX[] tva = new Native.TRIVERTEX[2];
			tva[0] = new Native.TRIVERTEX(rc.X, rc.Y, startColor);
			tva[1] = new Native.TRIVERTEX(rc.Right, rc.Bottom, endColor);
			Native.GRADIENT_RECT[] gra = new Native.GRADIENT_RECT[] {
    new Native.GRADIENT_RECT(0, 1)};

			// Get the hDC from the Graphics object.
			IntPtr hdc = gr.GetHdc();

			// PInvoke to GradientFill.
			bool b;

			b = Native.GradientFill(
					hdc,
					tva,
					(uint)tva.Length,
					gra,
					(uint)gra.Length,
					(uint)fillDir);
			System.Diagnostics.Debug.Assert(b, string.Format(
				"GradientFill failed: {0}",
				System.Runtime.InteropServices.Marshal.GetLastWin32Error()));

			// Release the hDC from the Graphics object.
			gr.ReleaseHdc(hdc);

			return b;
		}

		// The direction to the GradientFill will follow
		public enum FillDirection
		{
			//
			// The fill goes horizontally
			//
			LeftToRight = (int)Native.GRADIENT_FILL_RECT_H,
			//
			// The fill goes vertically
			//
			TopToBottom = (int)Native.GRADIENT_FILL_RECT_V
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -