-
Property Grid
ُسلام من یه سوال درباره ی Property Grid داره
من یه Object دارم می خوام خواص اون رو باهاش تغییر بدم
من اول اینو می نویسم که خواصشو بریزه تو Property Grid مون
property.selectObject = Object;
خوب حالا گرید مون خواص ابجکت رو نشون می ده ولی تغییراتی که می دیم به Object اعمال نمی کنه باید چی کنم ؟
که هر تغییری در خواص گرید مون می دیم اون خواص اون ابجکت هم تغییر کنه
-
سلام
نیاز به کار خاصی نیست، اگر شی شما یک class باشد، چون ارجاعی است، تغییرات در همان لحظه اعمال خواهد شد، بدیهی است که اگر شی struct باشد با هر انتقال یک کپی جدید از شی منتقل میشود.
شی تان class است یا struct ؟
-
-
سلام
بدون شک جایی را اشتباه کرده اید... لطفاً دقت بیشتری کنید.
کلاس تان چیست؟
میتوانید کد نمونه اپلود کنید؟
اگر بخواهید به راحتی میتوانم یک سمپل برایتان آپلود کنم...
-
نه نیاز به نمونه نیست من واسه کلاس های دیگه استفاده می کنم جواب می ده
کلاسم سادست چیز خاصی نداره
کد:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using FarseerGames.FarseerPhysics.Collisions;
using FarseerGames.FarseerPhysics.Controllers;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Factories;
using FarseerGames.FarseerPhysics.Interfaces;
using FarseerGames.FarseerPhysics.Mathematics;
using FarseerGames.FarseerPhysics;
namespace xna_Application
{
class GameObject
{
#region Variable
Body Body = new Body();
Geom Geom = new Geom();
Texture2D texture;
Microsoft.Xna.Framework.Vector2 position;
float mass;
FarseerGames.FarseerPhysics.Mathematics.Vector2 move = new FarseerGames.FarseerPhysics.Mathematics.Vector2(0, 0);
bool _Static;
float rotation;
int width;
int height;
// if Select Circle Shape
int radius;
int edge;
float friction;
float restitution;
#endregion
GraphicsDevice Device;
#region Peropertice
public float Mass
{
set { mass = value; }
get { return mass; }
}
public FarseerGames.FarseerPhysics.Mathematics.Vector2 Move
{
set { move = value; }
get { return move; }
}
public string Texture
{
set { texture = Texture2D.FromFile(Device, value); }
}
public bool Static
{
set { _Static = value; }
get { return _Static; }
}
public Microsoft.Xna.Framework.Vector2 Position
{
set
{
position = value;
}
get
{
return position;
}
}
public float Rotation
{
set { rotation = value; }
get { return rotation; }
}
public int Height
{
get { return height; }
set { height = value; }
}
public int Width
{
set { width = value; }
get { return width; }
}
public int Radius
{
set { radius = value; }
get { return radius; }
}
public int Edge
{
set { edge = value; }
get { return edge; }
}
public float Restitution
{
get { return restitution; }
set { restitution = value; }
}
public float Friction
{
set { friction = value; }
get { return friction; }
}
#endregion
#region Method
public void Create(PhysicsSimulator World, ShapeBody Shape,GraphicsDevice _Device)
{
Device = _Device;
if (Shape == ShapeBody.Circle)
{
Body = BodyFactory.Instance.CreateCircleBody(World, radius, mass);
Body.Position = new FarseerGames.FarseerPhysics.Mathematics.Vector2(position.X, position.Y);
Body.Rotation = rotation;
Body.IsStatic = _Static;
Geom = GeomFactory.Instance.CreateCircleGeom(World, Body, radius, edge);
Geom.FrictionCoefficient = friction;
Geom.RestitutionCoefficient = restitution;
World.Add(Body);
}
else
{
Body = BodyFactory.Instance.CreateRectangleBody(World, width, height, mass);
Body.Position = new FarseerGames.FarseerPhysics.Mathematics.Vector2(position.X, position.Y);
Body.Rotation = rotation;
Body.IsStatic = _Static;
Geom = GeomFactory.Instance.CreateRectangleGeom(World, Body, width, height);
Geom.FrictionCoefficient = friction;
Geom.RestitutionCoefficient = restitution;
World.Add(Body);
}
}
public void Update()
{
Body.ApplyForce(move);
move = new FarseerGames.FarseerPhysics.Mathematics.Vector2(0, 0);
position = new Microsoft.Xna.Framework.Vector2(Body.Position.X, Body.Position.Y);
}
public void Draw(SpriteBatch SpriteBatch)
{
SpriteBatch.Begin();
SpriteBatch.Draw(texture, new Microsoft.Xna.Framework.Vector2(Geom.Position.X, Geom.Position.Y), new Rectangle(0, 0, texture.Width, texture.Height), Color.White, Geom.Rotation, new Microsoft.Xna.Framework.Vector2(texture.Width / 2, texture.Height / 2), 1f, SpriteEffects.None, 0f);
SpriteBatch.End();
}
#endregion
#region enum
public enum ShapeBody
{
Rectangle
,
Circle
}
#endregion
}
}
کلاس فرم من معمولی نیست این چند تا چیز که می زارم ببینید مشکل از اینا نیست
اسم فرم من Program است هم کلاس Program توشه هم فرم .
[html] public partial class Program : Form, IServiceProvider, IGraphicsDeviceService
{[/html]
کد:
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
using (Program form = new Program())
{
int Time = 0;
while (form.Created)
{
Time = Environment.TickCount;
form.Update(Time);
form.Draw(Time);
Application.DoEvents();
}
}
بعد یه متغیر از اون کلاس تعریف کردم
کد:
GameObject obj = new GameObject();
بعدشم در Intialize
کد:
PropertyObject.SelectedObject = obj;
خیلی ممنون
در ضمن مشکلش با کلاسم نیست با بقیه ی چیز ها هم مشکل داره
با این کنترل ها فقط کار می کنه
-
سلام
حتماً دوبار new میکنید...
به این نمونه دقت کنید:
خواهید دید که به وضوح با تغییر Rotation مقدار ان در برنامه تغییر میکند و با کلیک دکمه موجود، مقدار جاری که ناشی از تغییر اعمال شده در PropertyGrid است نشان داده خواهد شد:
این کد به وضوح صحت عملکرد PropertyGrid را نشان میدهد...
فراموش نکنید که اگر دو بار New کنید، دو شی ساخته اید و مثل ان میماند که دو TextBox داشته باشید! هر TextBox میتواند رنگ و فونت و عرض و... خودش را داشته باشد.
(9 کیلوبایت)
rapidshare.com/files/244720376/WindowsFormsApplication1.zip
=====
در نهایت در مورد کد اصلی تان هم باید بگویم شما نیازی به ایجاد حلقه while در متد main ندارید...
بهتر است یک وراثت از Microsoft.Xna.Framework.Game بگیرید و در main متد Run این کلاس را اجرا کنید.
کلاس فوق خودش پیاده سازی هایی برای Update و Draw و... دارد.
=====
موفق باشید.
-
خیلی ممنون
من دوبار New نکردم
فقط یه باره دومی کو ؟
----------------
خوشمان امد
شما هم ؟
اگه این کاری که شما می گید رو انجام بدم دیگه نمی تونم از کنترل ها و .... استفاده کنم
یه کاری کردم که هم بشه از Xna استفاده کرد هم از کنترل ها و ....
امتحان کردم نشد
یه جوری درستش کردم ولی اصولی نیست
زیاد درست سر داره
-
سلام
نقل قول:
فقط یه باره دومی کو ؟
شما باید در کدتان پیدایش کنید...
همانطور که در کد نمونه خواهید دید با یکبار new و حفظ اشاره گر به صورت عمومی (که نیاز به new مجدد نباشد) PropertyGrid کار خود را انجام خواهد داد و کاری به نمونه شی ندارد.
بله ولی اصولاً مخلوط کار کردن این تیپی شاید چندان مرسوم نباشد.