private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog opf = new OpenFileDialog();
opf.Filter = "JPG|*.jpg|BMP|*.bmp|PNG|*.png";
if (opf.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(opf.FileName);
}
}
public class PictureBox : Control
{
public PictureBox()
{
Click += delegate {
MessageBox.Show("This is a picture box");
}
}
}
public void ShowImage(Image img)
{
// ...
}
ShowImage(myImage);
public void Add(int a, int b)
{
Console.WriteLine(a + b);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
int x = (sender as PictureBox).Location.X;
int y = (sender as PictureBox).Location.Y;
int width = (sender as PictureBox).Width;
int height= (sender as PictureBox).Height;
if (x < 0 || x > this.Width - width)
{
x = 0;
}
if (y < 0 || y > this.Height - height)
{
y = 0;
}
(sender as PictureBox).Location = new Point(x, y);
}
public static void setText(TextBlock tb, string text)
{
tb.Text = text;
}
public void WriteToText(string imgPath)
{
var binaryWriter = new BinaryWriter(new FileStream("C:\\Users\\Emmett\\Desktop\\1.txt", FileMode.OpenOrCreate));
binaryWriter.Write(imgPath);
binaryWriter.Close();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CSharp_WinForm_Picturebox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
MessageBox.Show("You Clicked the PictureBox");
}
}
}
var fs = require('fs');
var request = require('request');
var url = 'http://img.mukewang.com/59b4f61e0001d8ed06000338.jpg';
var write = fs.createWriteStream('./demo.jpg');
request.get(url).pipe(write);
write.on('finish', function () {
console.log('success');
});
// 引用
using System.Drawing; // 这里使用了系统绘图库,其中包含了一些绘图功能
// 自定义一个类并且继承自一个系统类,这里指PictureBox
// 注意,这里我们使用了:,因此我们需要使用{}来指明参数的作用域,其作用域就是它的子类
class MyPicture : PictureBox
{
// 构造函数,构造函数是在生成这个类的时
public class MyCustomControl : WebControl
{
public void CustomFunction()
{
// Do Something
}
}
public void btn_Click(object sender, EventArgs e)
{
this.BackColor = Color.Red;
}
pictureBox1.Click += new EventHandler(btn_Click);
public class CustomButton : Button
{
public void PerformClick()
{
// do something
}
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile("图片地址");
}
public class MyButton : Button
{
public event EventHandler<MyButton> MyClick;
//自定义一个 MyClick
private void OnMyClick(MyButton myButton)
{
if (MyClick != null)
{
MyClick(this, myButton);
}
}
}
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
Image image = Image.FromFile(@"C:\path\to\image.jpg");
Bitmap bitmap = new Bitmap(image, new Size(200, 200));
bitmap.Save(@"C:\path\to\image.jpg", ImageFormat.Jpeg);
public static void SaveImageToFile(Image image, string filePath, ImageFormat format)
{
// Ensure the quality parameter is valid.
if ((quality < 0) || (quality > 100))
{
throw new ArgumentOutOfRangeException("quality", "The quality parameter must be between 0 and 100.");
}
// Create an image encoder for this format.
ImageCodecInfo codec = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == format.Guid);
// Create an Encoder object based on the GUID
// for the Quality parameter category.
Encoder encoder = Encoder.Quality;
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
EncoderParameters encoderParameters = new EncoderParameters(1);
EncoderParameter encoderParameter = new EncoderParameter(encoder, quality);
encoderParameters.Param[0
using System.Drawing;
using System.Windows.Forms;
public class PictureBox : PictureBox
{
public PictureBox(){
this.Click += new EventHandler(this.PictureBox_Click);
}
private void PictureBox_Click(object sender, EventArgs e){
MessageBox.Show("Hello World");
}
}
myControl.myFunc = myFunc;
public string AutoText
{
get { return autoTextBox.Text; }
set { autoTextBox.Text = value; }
}
<font color=#00ffff size=5>The function SelectList takes 4 arguments:
the first argument is the list<Lesson> lessons,the second and third are the ID and Name of lesson,the fourth is the selectLessonID.
</font>
The w is an instance of the WlanClient class.
private void button1_Click(object sender, EventArgs e)
{
string filename = @"C:\Users\zxy\Desktop\a.jpg";
Image image = Image.FromFile(filename);
pictureBox1.Image = image;
}
Func<BitmapSource, BitmapSource> loadImage =
(source) => new BitmapImage(source);
loadImage(new Uri("http://www.example.com/image.png"));
public static void WriteImageFile(string filePath, byte[] imageData)
{
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
bw.Write(imageData);
}
}
}
Script
function writeImageToDoc(url) {
var image = new Image();
image.src = url;
image.onload = function() {
var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
var context = canvas.getContext("2d");
context.drawImage(this, 0, 0, image.width, image.height);
var dataURL = canvas.toDataURL("image/png");
document.write(dataURL);
};
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}