| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2058 人关注过本帖
标题:请教高手:如何实现动态加载自定义控件的时候实现控件旋转一定角度再加载
只看楼主 加入收藏
yianyxl
Rank: 2
等 级:论坛游民
帖 子:7
专家分:12
注 册:2010-12-1
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:5 
请教高手:如何实现动态加载自定义控件的时候实现控件旋转一定角度再加载
我的程序是这样的,一个Form,内含一个pictureBox,在某个循环下
while(……)
{
   ……
   MyControl myControl=new MyControl;
   myControl.Loacation=new Point(……);
   this.pictureBox.Controls.Add(myControl);
   ……
}

我自定义的控件MyControl其实就是一个小图片,现在想在加载到pictureBox中的时候旋转一定的角度(其实就是pictureBox中画了个斜线,在斜线上实现该控件的放置与其平行),希望有高手能给出个思路方法,不胜感激
搜索更多相关主题的帖子: 不胜感激 
2011-09-21 15:01
刘杰明
Rank: 8Rank: 8
来 自:山东大学威海校区
等 级:蝙蝠侠
帖 子:155
专家分:872
注 册:2011-6-20
收藏
得分:7 
...........

______________________________加油__!__!___!
2011-09-28 10:18
xydddaxia
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:33
帖 子:466
专家分:2307
注 册:2009-3-20
收藏
得分:7 
程序代码:
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;


public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
        private Bitmap img;
        private float rot = 0F;
        /// <summary>
        /// 图片
        /// </summary>
        public Bitmap Img
        {
            get { return img; }
            set { img = value; }
        }
        /// <summary>
        /// 旋转角度
        /// </summary>
        public float Rot
        {
            get { return rot; }
            set
            {
                rot = value;
                this.Invalidate();
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (this.img != null)
            {
                Graphics g = this.CreateGraphics();
                if (rot != 0F)
                {
                    g.DrawImage(ImageRotate(img, rot, this.BackColor), new Point(0, 0));
                }
                else
                {
                    g.DrawImage(img, new Point(0, 0));
                }
            }
        }

        /// <summary> 
        /// 任意角度旋转 
        /// </summary> 
        /// <param name="bmp">原始图Bitmap </param> 
        /// <param name="angle">旋转角度 </param> 
        /// <param name="bkColor">背景色 </param> 
        /// <returns>输出Bitmap </returns> 
        public static Bitmap ImageRotate(Bitmap p_Image, float p_Angle, Color p_BlackColor)
        {
            int _Width = p_Image.Width + 2;
            int _Height = p_Image.Height + 2;

            PixelFormat _BitmapPixelFormat = PixelFormat.Format32bppArgb;

            if (p_BlackColor != Color.Transparent) _BitmapPixelFormat = p_Image.PixelFormat;

            Bitmap _OldBitmap = new Bitmap(_Width, _Height, _BitmapPixelFormat);
            Graphics _Graphics = Graphics.FromImage(_OldBitmap);
            _Graphics.Clear(p_BlackColor);
            _Graphics.DrawImageUnscaled(p_Image, 1, 1);
            _Graphics.Dispose();

            GraphicsPath _Path = new GraphicsPath();
            _Path.AddRectangle(new RectangleF(0f, 0f, _Width, _Height));
            Matrix _Mtrx = new Matrix();
            _Mtrx.Rotate(p_Angle);
            RectangleF _Rect = _Path.GetBounds(_Mtrx);

            Bitmap _NewBitmap = new Bitmap((int)_Rect.Width, (int)_Rect.Height, _BitmapPixelFormat);
            _Graphics = Graphics.FromImage(_NewBitmap);
            _Graphics.Clear(p_BlackColor);
            _Graphics.TranslateTransform(-_Rect.X, -_Rect.Y);
            _Graphics.RotateTransform(p_Angle);
            _Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
            _Graphics.DrawImageUnscaled(_OldBitmap, 0, 0);
            _Graphics.Dispose();

            _OldBitmap.Dispose();

            return _NewBitmap;
        }
    }


[ 本帖最后由 xydddaxia 于 2011-9-28 13:44 编辑 ]

站在春哥的肩膀上
2011-09-28 12:07
Stella中女
Rank: 1
等 级:新手上路
帖 子:2
专家分:7
注 册:2011-9-28
收藏
得分:7 
namespace Teacher
{
    class Teacher
    {
        static void Main(string[] args)
        {
        }
    }
}
如果我想定义一个教师类,这部分
static void Main(string[] args)
        {
        }

能不能不要,然后自己定义内容,然后再运行?
2011-09-28 18:45
fzm2001
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-3-29
收藏
得分:0 
javascript:insertText('13','tk');
我也想知道
2016-03-29 16:34
fzm2001
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-3-29
收藏
得分:0 
最后成功没有,怎么实现的,贴出来学习学习。
2016-03-29 18:01
快速回复:请教高手:如何实现动态加载自定义控件的时候实现控件旋转一定角度再加 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012364 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved