C#开发WPF/Silverlight动画及游戏系列教程(Game Course):(三十四)地图编辑器诞生啦!
2010-09-30 21:02:10 来源:WEB开发网第二步,设计功能
1)载入地图:
通过OpenFileDialog来开启一个文件选择对话框,并通过文件选择过滤器Filter限制加载图片的类型为*.jpg和*.png:
//载入地图
private void LoadMap_Click(object sender, RoutedEventArgs e) {
OpenFileDialog loadMap = new OpenFileDialog() {
CheckFileExists = true,
CheckPathExists = true,
Multiselect = false,
Filter = "图像文件(*.jpg,*.png)|*.jpg;*.png",
};
loadMap.FileOk += new System.ComponentModel.CancelEventHandler(loadMap_FileOk);
loadMap.ShowDialog();
}
2)布局网格:
为了可以适应不同GridSize尺寸的需要,我们需要更加灵活的网格模型,因此选择Grid做为主体,当加载完地图后,我们可以根据该地图的相关数据自动在画板ScrollViewer中动态添加Grid(包括行数和列数):
……
grid = new Grid() {
ShowGridLines = ShowGrid.IsChecked.Value,
Width = width,
Height = height,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
};
GridWidth.Text = gridWidth.ToString();
GridHeight.Text = gridHeight.ToString();
for (int x = 0; x < grid.Width / gridWidth; x++) {
ColumnDefinition col = new ColumnDefinition() {
Width = new GridLength(gridWidth),
};
grid.ColumnDefinitions.Add(col);
}
for (int y = 0; y < grid.Height / gridHeight; y++) {
RowDefinition row = new RowDefinition() {
Height = new GridLength(gridHeight),
};
grid.RowDefinitions.Add(row);
}
scrollViewer.Content = grid;
……
Tags:开发 WPF Silverlight
编辑录入:爽爽 [复制链接] [打 印]- ››开发Android 日历教程
- ››开发学院总结 Win 8实用技巧大全
- ››开发学院原创教程:把win8的IE10放桌面上方法(非...
- ››silverlight全屏显示图片
- ››Silverlight MVVM 模式(一) 切近实战
- ››开发者眼中的Windows Phone和Android
- ››开发学院教你用SQL 语句最快速清空MySQL 数据表的...
- ››WPF学习笔记12. Binding (5)
- ››WPF学习笔记11. Binding (4)
- ››WPF学习笔记10. Binding (3)
- ››WPF学习笔记9. Binding (2)
- ››WPF学习笔记8. Binding
更多精彩
赞助商链接